General reminders |
To display a Swing component, you must:
Container contentPane = getContentPane(); contentPane.add (button,BorderLayout.SOUTH); ... contentPane.validate();
JPanels use FlowLayout, which does not allow a section of the screen to be specified, so the second parameter of the add method must be omitted when adding to a panel.
To handle events from a GUI component, you must do the following:
When the listener method is called, you can find out which component sent the event by calling getSource() on the event.
public void actionPerformed (ActionEvent event) { Object theButton = event.getSource(); if (theButton == framedCircleButton) { // Create a framed circle } }
If a method returns a String or Object, remember to compare the result using the equals method, not ==. For example, aMenu.getSelectedItem ().equals ("A value")
General reminders |