import javax.swing.JFrame; import javax.swing.JButton; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.FlowLayout; class Program01 extends JFrame implements ActionListener { JButton okButton = new JButton("Ok"); JButton cancelButton = new JButton("Mégsem"); String OK_COMMAND = "ok"; String CANCEL_COMMAND = "cancel"; Program01() { okButton.addActionListener(this); okButton.setActionCommand(OK_COMMAND); cancelButton.addActionListener(this); cancelButton.setActionCommand(CANCEL_COMMAND); add(okButton); add(cancelButton); setLayout(new FlowLayout()); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(400, 300); setVisible(true); } public static void main(String args[]) { new Program01(); } public void actionPerformed(ActionEvent e){ if(e.getActionCommand().equals(OK_COMMAND)){ setTitle("Ok"); }else if(e.getActionCommand().equals(CANCEL_COMMAND)){ setTitle("Nem jó"); } } }