Class SwingDemo

All Implemented Interfaces:
ActionListener, EventListener

public class SwingDemo
extends Object
implements ActionListener

Create a JTextField and some JButtons to control it

Constructor Summary
Method Summary
 void actionPerformed(ActionEvent e)
          React to buttons that are pressed.
protected  JPanel makeButtonRow(String[] labels)
          Return a JPanel that contains buttons with the specified labels.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public SwingDemo()
Method Detail


public void actionPerformed(ActionEvent e)
React to buttons that are pressed. See the example in class and in the applet

Specified by:
actionPerformed in interface ActionListener


protected JPanel makeButtonRow(String[] labels)
Return a JPanel that contains buttons with the specified labels.

Reminder: you can call this method as follows:

makeButtonRow(new String[] {"red", "blue", "green", "black"});

This method can be done as follows:

  1. Instantiate a JPanel (call this ans) that you will return at the end of this method
  2. Iterate over the String array
    1. Instantiate a (local) JButton with the appropriate label.
    2. Add this class as an ActionListener to the JButton using addActionListener.
    3. Add the JButton to the ans JPanel