Arrays in JavaTopFinishing GUI

Finishing GUI

As we saw from last time to insert a GUI item on the screen we must:

  1. Create the item and initialize it if necessary.
  2. Add the items to the window or a JPanel, and validate the window.

If we want selecting the GUI object to trigger an immediate response we must:

  1. Associate one or more listeners with the GUI object.
  2. Make sure the listening class implements the appropriate listener interface
  3. Wrote the appropriate method to respond to the event

We've spoken mainly about JComboBoxes, but we can also work with JButtons, JLabel, JSlider, JTextField, and JTextArea. See the documentation on the GUI cheat sheet on the course documentation page.

Remember when you add items to the window, use the BorderLayout, which requires you to state where in the window you place the item (NORTH, SOUTH, EAST, or WEST) while JPanels use FlowLayout and you leave off the place information.

When executing an event handling method, you can find out what GUI component generated the event by evaluating evt.getSource() if evt is the event.


Arrays in JavaTopFinishing GUI