?? frame1.java~14~
字號:
package serialize;import java.awt.*;import java.awt.event.*;import javax.swing.*;import com.borland.jbcl.layout.*;import java.io.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2006</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class Frame1 extends JFrame { JPanel contentPane; XYLayout xYLayout1 = new XYLayout(); JLabel jLabel2 = new JLabel(); JTextField jTextField1 = new JTextField(); JTextField jTextField2 = new JTextField(); JButton jButton1 = new JButton(); JButton jButton2 = new JButton(); JLabel jLabel1 = new JLabel(); //Construct the frame public Frame1() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { contentPane = (JPanel) this.getContentPane(); jLabel1.setVerifyInputWhenFocusTarget(true); jLabel1.setText("user"); contentPane.setLayout(xYLayout1); this.setSize(new Dimension(400, 300)); this.setTitle("Frame Title"); contentPane.setToolTipText(""); jLabel2.setText("password"); jButton1.setText("Serialize"); jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this)); jButton2.setText("jButton2"); jButton2.addActionListener(new Frame1_jButton2_actionAdapter(this)); jLabel1.setText("username"); jTextField1.setText(""); jTextField2.setText(""); contentPane.add(jLabel1, new XYConstraints(74, 47, 93, 19)); contentPane.add(jLabel2, new XYConstraints(73, 92, 96, 15)); contentPane.add(jTextField1, new XYConstraints(202, 48, 110, 19)); contentPane.add(jTextField2, new XYConstraints(201, 86, 114, 18)); contentPane.add(jButton1, new XYConstraints(84, 139, 81, 16)); contentPane.add(jButton2, new XYConstraints(204, 137, 93, 18)); contentPane.add(jLabel1, new XYConstraints(74, 47, 46, -1)); } //Overridden so we can exit when window is closed protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } void jButtonSerialize_actionPerformed(ActionEvent e) { User user=new User(); //獲取文本框中輸入的用戶名和密碼設置到對象中去 user.setUsername(jTextField1.getText()); user.setUserPassword(jTextField2.getText()); try{ FileOutputStream file=new FileOutputStream ("d:\\userinfo.txt"); ObjectOutputStream out=new ObjectOutputStream(file); out.writeObject(user); out.flush(); out.close(); }catch(java.io.IOException ioe){ JOptionPane.showMessageDialog(this,ioe.toString()); } finally{ JOptionPane.showMessageDialog(this,"Serialize succeed"); } } void jButtonDeserialize_actionPerformed(ActionEvent e) { try{ FileInputStream file=new FileInputStream ("d:\\userinfo.txt"); ObjectInputStream input=new ObjectInputStream(file); User user=(User)input.readObject(); input.close(); jTextField1.setText(user.getUsername()); jTextField2.setText(user.getUserPassword()); }catch(java.io.IOException ioe)//文件 { JOptionPane.showMessageDialog(this,ioe.toString()); } catch(ClassNotFoundException cnfe){ JOptionPane.showMessageDialog(this,cnfe.toString()); } }}class Frame1_jButton1_actionAdapter implements java.awt.event.ActionListener { Frame1 adaptee; Frame1_jButton1_actionAdapter(Frame1 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButtonSerialize_actionPerformed(e); }}class Frame1_jButton2_actionAdapter implements java.awt.event.ActionListener { Frame1 adaptee; Frame1_jButton2_actionAdapter(Frame1 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButtonDeserialize_actionPerformed(e); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -