📄 mainframe.java~7~
字号:
package jobjectstreamdemo;import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.util.*;public class MainFrame extends JFrame { private JPanel contentPane; private BorderLayout borderLayout1 = new BorderLayout(); private JPanel jPanel1 = new JPanel(); private JButton jButton1 = new JButton(); private JButton jButton2 = new JButton(); //DataObject dataObject = new DataObject(); File file = null ; FileOutputStream fos = null; FileInputStream fis = null; ObjectOutputStream oos = null; ObjectInputStream ois = null; Hashtable ht = new Hashtable(); String[][] data = {{"ID","008"},{"Name","Zhou Xingchi"},{"age","30"},{"Address","HongKong"}}; private JScrollPane jScrollPane1 = new JScrollPane(); private JTextArea jTextArea1 = new JTextArea(); //Construct the frame public MainFrame() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { for (int i=0;i<data.length;i++){ ht.put(data[i][0],data[i][1]); this.jTextArea1.append(data[i][0]+"="+data[i][1]+"\n"); } //setIconImage(Toolkit.getDefaultToolkit().createImage(MainFrame.class.getResource("[Your Icon]"))); contentPane = (JPanel) this.getContentPane(); contentPane.setLayout(borderLayout1); this.setSize(new Dimension(382, 112)); this.setTitle("JObjectStreamDemo"); jButton1.setText("Save"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton1_actionPerformed(e); } }); jButton2.setText("Read"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton2_actionPerformed(e); } }); contentPane.add(jPanel1, BorderLayout.SOUTH); jPanel1.add(jButton1, null); jPanel1.add(jButton2, null); contentPane.add(jScrollPane1, BorderLayout.CENTER); jScrollPane1.getViewport().add(jTextArea1, null); } //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 jButton2_actionPerformed(ActionEvent e) { } void jButton1_actionPerformed(ActionEvent e) { try{ file = File.createTempFile("DataObject",".tmp"); }catch(Exception err){ err.printStackTrace(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -