To make a button work it must be connected to an event listener:
public class ControlPanel
extends javax.swing.JPanel
implements java.awt.event.ActionListener
{
JButton okButton = new JButton ("OK");
JButton cancelButton = new JButton ("Cancel");
public ControlPanel ()
{
add (okButton);
okButton.addActionListener (this);
add (cancelButton);
cancelButton.addActionListener (this);
}
public void actionPerformed (java.awt.event.ActionEvent event)
{
JButton source = (JButton) event.getSource (); // Safe?
if (source.equals (okButton))
{
process ();
}
else
{
cancel ();
}
}
}
Menu options also use ActionListener
.