问题描述
- 求大神帮我将代码简化(本人还处在学习阶段,都是自学的)
- package Test;
import java.awt.BorderLayout;
public class Ftest 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 closeButton = null;/** * Launch the application. */public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { Ftest thisclass = new Ftest(); thisclass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);; thisclass.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } });}/** * Create the frame. */public Ftest() { initianlize(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100 100 450 300); controlPanel = new JPanel(); controlPanel.setBorder(new EmptyBorder(5 5 5 5)); setContentPane(controlPanel); controlPanel.setLayout(null); final JTextArea jTextArea = new JTextArea(); jTextArea.setBounds(10 10 414 215); controlPanel.add(jTextArea); JButton openButton = new JButton(""u5199u5165u6587u4EF6"");//写入文件 openButton.setBounds(72 229 93 23); controlPanel.add(openButton); openButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub File file = new File(""D:/Workspase/Input_Output/world.txt""); try{ FileWriter out = new FileWriter(file); String s = jTextArea.getText(); out.write(s); out.close(); }catch(Exception e1){ e1.printStackTrace(); } } }); JButton closeButton = new JButton(""u8BFBu53D6u6587u4EF6"");//读取文件 closeButton.setBounds(247 229 93 23); controlPanel.add(closeButton); closeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub File file = new File(""D:/Workspase/Input_Output/world.txt""); try{ FileReader in = new FileReader(file); char byt[] = new char[1024]; int len = in.read(byt); jTextArea.setText(new String(byt0len)); in.close(); }catch(Exception e1){ e1.printStackTrace(); } } });}private void initianlize() { // TODO Auto-generated method stub this.setSize(300200); this.setContentPane(getContentPane()); this.setTitle(""JFrame"");}private JPanel getJContentPane(){ if(jContentPane == null){ jContentPane = new JPanel(); jContentPane.setLayout(new BorderLayout()); jContentPane.add(getJTextArea()BorderLayout.CENTER); jContentPane.add(getControlPanel()BorderLayout.SOUTH); } return jContentPane;}private Component getControlPanel() { // TODO Auto-generated method stub return null;}private Component getJTextArea() { // TODO Auto-generated method stub return null;}
}
解决方案
做100件事的代码量一般是和做1件事的代码量不一样的,简化的话功能就少了
解决方案二:
java做c/s 不如.net, b/s 还不错。 换成C#来搞吧。
时间: 2024-12-21 22:17:07