Ee3206ee5805 java programming applications 37 example

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: are provided in the class, but omitted in the UML diagram for brevity. EE3206/EE5805 Java Programming & Applications 37 Example: Using Sliders Rewrite the preceding program using the sliders to control a message displayed on a panel instead of using scroll bars. SliderDemo Run EE3206/EE5805 Java Programming & Applications 38 Creating Multiple Windows The following slides show step-by-step how to create an additional window from an application or applet. Step 1: Create a subclass of JFrame (called a SubFrame) that tells the new JFrame SubFrame window what to do. For example, all the GUI application programs extend JFrame and are subclasses of JFrame. JFrame JFrame Step 2: Create an instance of SubFrame in the application or applet. SubFrame Example: SubFrame subFrame = new SubFrame("SubFrame Title"); EE3206/EE5805 Java Programming & Applications 39 Creating Multiple Windows Step 3: Create a JButton for activating the subFrame. JButton subFrame add(new JButton("Activate SubFrame")); Step 4: Override the actionPerformed() method to make the actionPerformed additional window visible as follows: public actionPerformed(ActionEvent e) { String actionCommand = e.getActionCommand(); if ("Activate SubFrame".equals(actionCommand)) { subFrame.setVisible(true); } } EE3206/EE5805 Java Programming & Applications 40 Example: Creating Multiple Windows This example creates a main window with a text area in the scroll pane, and a This button named "Show Histogram." When the user clicks the button, a new window appears that displays a histogram to show the occurrence of the letters in the text area. MultipleWindowsDemo Run Histogram EE3206/EE5805 Java Programming & Applications 41...
View Full Document

This note was uploaded on 01/11/2011 for the course EE 3206 taught by Professor Cwting during the Spring '07 term at City University of Hong Kong.

Ask a homework question - tutors are online