⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frame1.java~7~

📁 这是一个关于java中对象的串行化例子
💻 JAVA~7~
字号:
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("jLabel2");    jButton1.setText("Serialize");    jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));    jButton2.setText("jButton2");    jLabel1.setText("jLabel1");    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");       } }}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);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -