package mypackage1;import javax.swing.event.MenuListener;import javax.swing.event.*;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;import javax.swing.*;import java.util.*;import java.beans.*;import java.lang.*;import java.io.*;import java.awt.event.*;public class gui extends JFrame implements ActionListener { //JTextPane pane= new JTextPane(); public void serialize( String filename ) { try { XMLEncoder o = new XMLEncoder(new FileOutputStream(filename)); o.writeObject( "Today" ); o.writeObject( new Date() ); o.close(); } catch ( IOException e ) { } } public void deserialize( String filename ) { try { XMLDecoder o = new XMLDecoder( new FileInputStream(filename) ); String string = (String) o.readObject(); Date date = (Date) o.readObject(); o.close(); System.out.println(date); } catch ( IOException e ) { } } public gui() { super("task manager"); JTextPane pane= new JTextPane(); JMenuBar mb=new JMenuBar(); JMenu menu=new JMenu("Datei"); menu.add(new JMenuItem("Oeffnen")); menu.add(new JMenuItem("Speichern")); menu.add(new JMenuItem("Schliessen")); mb.add(menu); menu=new JMenu("Hilfe"); menu.add(new JMenuItem("Ueber")); mb.add(menu); this.setJMenuBar(mb); getContentPane().add(pane); pack(); setVisible(true); setSize(400,400); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(-1); } }); } public JMenuItem newMenuItem(String label) { JMenuItem m=new JMenuItem(label); m.addActionListener(this); return m; } public void actionPerformed(ActionEvent e) { System.out.println("ActionEvent: "+e); Object oe=e.getSource(); if(oe instanceof JMenuItem) { JMenuItem mi=(JMenuItem)oe; if(mi.getText().equals("Schliessen")) { setVisible(false); System.exit(-1); } if(mi.getText().equals("Speichern")) { String filename = "c:/datum.ser.xml"; serialize( filename ); } if(mi.getText().equals("Oeffnen")) { String filename = "c:/datum.ser.xml"; deserialize( filename ); } if(mi.getText().equals("Ueber")) { JOptionPane.showMessageDialog( this, "copyright by t.kalbermatten\ncontact [email protected]" ); } } } public static void main(String[] args) { gui gui = new gui(); } }