/* Listing3707.java */ import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Listing3707 extends JFrame implements ActionListener { public Listing3707() { super("JButton"); addWindowListener(new WindowClosingAdapter(true)); Container cp = getContentPane(); cp.setLayout(new FlowLayout()); JPanel panel = new JPanel(); //OK-Button JButton okButton = new DefaultButton("OK", getRootPane()); okButton.addActionListener(this); panel.add(okButton); //Abbrechen-Button JButton cancelButton = new CancelButton("Abbrechen"); cancelButton.addActionListener(this); panel.add(cancelButton); //Hilfe-Button JButton helpButton = new JButton("Hilfe"); helpButton.setMnemonic('H'); helpButton.addActionListener(this); panel.add(helpButton); //Panel hinzufügen cp.add(panel); } public void actionPerformed(ActionEvent event) { System.out.println(event.getActionCommand()); } public static void main(String[] args) { Listing3707 frame = new Listing3707(); frame.setLocation(100, 100); frame.setSize(300, 100); frame.setVisible(true); } }