首页 > 代码库 > 为什么我的不显示按钮
为什么我的不显示按钮
package lianxi; import javax.swing.SwingUtilities; import java.awt.BorderLayout; import javax.swing.JPanel; import javax.swing.JFrame; import javax.swing.JTextPane; import javax.swing.JTextArea; import java.awt.GridBagLayout; import javax.swing.JButton; import java.awt.GridBagConstraints; import java.awt.FlowLayout; import java.awt.event.*; import java.io.*; public class Ftest1 extends JFrame { private static final long serialVersionUID=1L; private JPanel jContentPane=null; private JTextArea jTextArea=null; private JPanel controlPanel=null; private JButton openButton=null; private JButton colesButton=null; private JTextArea getJTextArea() { if (jTextArea == null) { jTextArea = new JTextArea(); } return jTextArea; } private JPanel getControlPanel() { if (controlPanel == null) { FlowLayout flowLayout = new FlowLayout(); flowLayout.setVgap(1); controlPanel = new JPanel(); controlPanel.setLayout(flowLayout); controlPanel.add(getOpenButton(), null); controlPanel.add(getCloseButton(), null); } return controlPanel; } private JButton getOpenButton(){ if(openButton==null){ openButton=new JButton(); openButton.setText("写入文件"); openButton.addActionListener(new java.awt.event.ActionListener(){ public void actionPerformed(java.awt.event.ActionEvent e){ File file=new File("word.txt"); try { FileWriter out= new FileWriter(file); String s=jTextArea.getText(); out.write(s); out.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); } return openButton; } private JButton getCloseButton(){ if(openButton==null){ openButton=new JButton(); openButton.setText("读取文件"); openButton.addActionListener(new java.awt.event.ActionListener(){ public void actionPerformed(java.awt.event.ActionEvent e){ File file=new File("word.txt"); try { FileReader in=new FileReader(file); char byt[]=new char[1024]; int len=in.read(byt); jTextArea.setText(new String(byt,0,len)); in.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); } return openButton; } public Ftest1(){ super(); initialize(); } private void initialize(){ this.setSize(300,200); this.setContentPane(getJContentPane()); this.setTitle("JFrame"); } private JPanel getJContentPane(){ if(jContentPane==null){ jContentPane=new JPanel(); jContentPane.setLayout(new BorderLayout()); jContentPane.add(getJTextArea(), BorderLayout.CENTER); jContentPane.add(getContentPane(),BorderLayout.SOUTH); } return jContentPane; } public static void main(String[] args) { Ftest1 thisClass=new Ftest1(); thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); thisClass.setVisible(true); } }
应该是上图结果我的为什么是下面这
个图
为什么我的不显示按钮
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。