import java.awt.event.*; import java.awt.*; import javax.swing.*; public class ActionComandTest extends JFrame implements ActionListener, WindowListener { public JButton okButton; public JButton abbrechenButton; public ActionComandTest () { okButton = new JButton ("O.K."); okButton.addActionListener(this); okButton.setActionCommand("O.K. Command"); abbrechenButton = new JButton ("Abbrechen"); abbrechenButton.addActionListener(this); abbrechenButton.setActionCommand("Abbrechen Command"); MyActionListener1 m = new MyActionListener1("Test"); okButton.addActionListener(m); JPanel panel = new JPanel(); panel.add (okButton); panel.add (abbrechenButton); Container c = getContentPane(); c.add(panel); addWindowListener(this); } public void actionPerformed (ActionEvent e) { if (e.getActionCommand()== "O.K. Command") { } if (e.getActionCommand()== "Abbrechen Command") { } } public void windowOpened(WindowEvent e) { } public void windowClosing(WindowEvent e) { System.exit(0); } public void windowClosed(WindowEvent e) { } public void windowIconified(WindowEvent e) { } public void windowDeiconified(WindowEvent e) { } public void windowActivated(WindowEvent e) { } public void windowDeactivated(WindowEvent e) { } public static void main (String[] args) { ActionComandTest act = new ActionComandTest(); act.pack(); act.setVisible(true); } }