Note:
Frame2.java and the associated Frame2App.java is at the end of this module, or download the entire archiveCommand Design Pattern
When a user clicks on a button, an ActionEvent object is delivered to the button. In order for the button to perform an application specific task, we must register an ActionEventListener to the button and program this event listener to perform the task we want. The ActionListener class is an example of what is called a "command" from the Command Design Pattern. The code to add an ActionListener to a button looks like:
myButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// code to perform a task goes here...
}
});The example Frame2 (source code at end of the module) shows how to dynamically change the layout manager for a JFrame by calling its setLayout(...) method resulting in a dynamic re-arrangement of the GUI components in the JFrame.










"Accessible versions of this collection are available at Bookshare. DAISY and BRF provided."