chapter 9: creating user interfaces what is javabean? what is javabean? jcomponent jcomponent...

52
Chapter 9: Creating User Interfaces What is What is JavaBean? JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea JTextArea JComboBox JComboBox JList JList JCheckBox JCheckBox JRadioButton JRadioButton Menus Creating Multiple Windows JScrollBar JScrollPane

Upload: ashley-stephens

Post on 03-Jan-2016

240 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

Chapter 9:Creating User Interfaces

What is JavaBean?What is JavaBean? JComponentJComponent JButtonJButton JLabelJLabel JTextFieldJTextField JTextAreaJTextArea JComboBoxJComboBox JListJList JCheckBoxJCheckBox JRadioButtonJRadioButton

Menus Creating Multiple

Windows JScrollBar JScrollPane

Page 2: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

What is a JavaBean?A JavaBean component is just a Java class that meets the following requirements.

Data membersMethodsConstructors public class

default constructorserializablemay have accessor methodsmay have registration methods

class

JavaBean Minimumrequirements

Optionalrequirements

Page 3: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

Why JavaBeans?

The JavaBeans technology was developed to enable the programmers to rapidly build applications by assembling objects and test them during design time, thus making reuse of the software more productive.

Page 4: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

JComponent Properties toolTipTexttoolTipText fontfont backgroundbackground foregroundforeground doubleBuffereddoubleBuffered borderborder preferredSizepreferredSize minimumSizeminimumSize maximumSizemaximumSize

Page 5: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

JButton

A A buttonbutton is a component that triggers an is a component that triggers an event when pressed. The following are event when pressed. The following are JButtonJButton non-default constructors: non-default constructors:

JButton(String text)JButton(String text)

JButton(String text, Icon icon)JButton(String text, Icon icon)

JButton(Icon icon)JButton(Icon icon)

Example 9.1: Using ButtonsExample 9.1: Using Buttons

RunRunButtonDemoButtonDemo

Page 6: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

JButton Properties texttext iconicon mnemonicmnemonic horizontalAlignmenthorizontalAlignment verticalAlignmentverticalAlignment horizontalTextPositionhorizontalTextPosition verticalTextPositionverticalTextPosition

Page 7: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

Responding to JButton Events

public void actionPerformed(ActionEvent e) public void actionPerformed(ActionEvent e) { { // Get the button label // Get the button label String actionCommand = e.getActionCommand();String actionCommand = e.getActionCommand();

// Make sure the event source is a button // Make sure the event source is a button if (e.getSource() instanceof JButton)if (e.getSource() instanceof JButton) // Make sure it is the right button// Make sure it is the right button if ("My Button".equals(actionCommand)if ("My Button".equals(actionCommand) System.out.println ("Button pressed!");System.out.println ("Button pressed!");}}

Page 8: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

JLabel

Labels are simple text strings used to label other components (usually text fields). The non-default constructors for labels are as follows:

JLabel(String text, int horizontalAlignment)

JLabel(String text)

JLabel(Icon icon)

JLabel(Icon icon, int horizontalAlignment)

Example 9.2: Using LabelsRunRunLabelDemoLabelDemo

Page 9: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

JLabel Properties texttext iconicon horizontalAlignmenthorizontalAlignment verticalAlignmentverticalAlignment

Page 10: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

JTextField

A A text fieldtext field is an input area where the user is an input area where the usercan type in characters. Text fields are usefulcan type in characters. Text fields are usefulin that they enable the user to enter in variable in that they enable the user to enter in variable data (such as a name or a description).data (such as a name or a description).

Example 9.3: Using Text FieldsExample 9.3: Using Text Fields

RunRunTextFieldDemoTextFieldDemo

Page 11: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

JTextField Constructors JTextField(int columns)JTextField(int columns)

Creates an empty text field with the Creates an empty text field with the specified number of columns.specified number of columns.

JTextField(String text)JTextField(String text)

Creates a text field initialized with the Creates a text field initialized with the specified text.specified text.

JTextField(String text, int columns)JTextField(String text, int columns)

Creates a text field initialized with theCreates a text field initialized with thespecified text and the column size.specified text and the column size.

Page 12: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

JTextField Properties texttext horizontalAlignmenthorizontalAlignment editableeditable columnscolumns

Page 13: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

JTextField Methods getText()getText()

Returns the string from the text field. Returns the string from the text field.

setText(String text)setText(String text)Puts the given string in the text field.Puts the given string in the text field.

setEditable(boolean editable)setEditable(boolean editable)Enables or disables the text field to be edited. Enables or disables the text field to be edited. By default, By default, editableeditable is is truetrue. .

setColumns(int)setColumns(int)Sets the number of columns in this text field.Sets the number of columns in this text field.The length of the text field is changeable. The length of the text field is changeable.

Page 14: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

JTextArea

If you want to let the user enter multiple If you want to let the user enter multiple lines of text, you cannot use text fields lines of text, you cannot use text fields unless you create several of them. The unless you create several of them. The solution is to use solution is to use JTextAreaJTextArea, which enables , which enables the user to enter multiple lines of text.the user to enter multiple lines of text.

Example 9.4: Using Text AreasExample 9.4: Using Text Areas

RunRunTextAreaDemoTextAreaDemo

Page 15: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

JTextArea Constructors JTextArea(int rows, int columns)JTextArea(int rows, int columns)

Creates a text area with the specified number Creates a text area with the specified number of rows and columns.of rows and columns.

JTextArea(String s, int rows, int columns)JTextArea(String s, int rows, int columns)

Creates a text area with the initial text andCreates a text area with the initial text andthe number of rows and columns specified.the number of rows and columns specified.

Page 16: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

JTextArea Properties texttext editableeditable columnscolumns lineWraplineWrap wrapStyleWordwrapStyleWord rowsrows lineCountlineCount tabSizetabSize

Page 17: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

JComboBox

A A combo boxcombo box is a simple list of items from is a simple list of items from which the user can choose. It performs which the user can choose. It performs basically the same function as a list, but basically the same function as a list, but can get only one value. To create a choice, can get only one value. To create a choice, use its default constructor:use its default constructor:

JComboBox()JComboBox()

Example 9.5: Using Combo BoxesExample 9.5: Using Combo Boxes

RunRunComboBoxDemoComboBoxDemo

Page 18: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

JComboBox Methods

To add an item to a To add an item to a JComboBox jcboJComboBox jcbo, use, use

jcbo.addItem(Object item)jcbo.addItem(Object item)

To get an item from To get an item from JComboBox jcboJComboBox jcbo, use, use

jcbo.getItem()jcbo.getItem()

Page 19: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

Using theitemStateChanged Handler

public void itemStateChanged(ItemEvent e) public void itemStateChanged(ItemEvent e) { { // Make sure the source is a combo box// Make sure the source is a combo box if (e.getSource() instanceof JComboBox)if (e.getSource() instanceof JComboBox) String s = (String)e.getItem();String s = (String)e.getItem();}}

When a choice is checked or unchecked, itemStateChanged() for ItemEvent is invoked as well as the actionPerformed() handler for ActionEvent.

Page 20: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

JList

A A listlist is a component that performs basically is a component that performs basically the same function as a combo box, but it the same function as a combo box, but it enables the user to choose a single value or enables the user to choose a single value or multiple values.multiple values.

Example 9.6: Using ListsExample 9.6: Using Lists

RunRunListDemoListDemo

Page 21: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

JList Constructors JList()JList()

Creates an empty list.Creates an empty list.

JList(Object[] stringItems)JList(Object[] stringItems)

Creates a new list initialized with items.Creates a new list initialized with items.

Page 22: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

JList Properties

selectedIndexdselectedIndexd

selectedIndicesselectedIndices

selectedValueselectedValue

selectedValuesselectedValues

selectionModeselectionMode

visibleRowCountvisibleRowCount

Page 23: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

JCheckBox

A A check boxcheck box is a component that enables the is a component that enables the user to toggle a choice on or off, like a light user to toggle a choice on or off, like a light switch. switch.

Example 9.7: Using Check BoxesExample 9.7: Using Check Boxes

CheckBoxDemoCheckBoxDemo RunRun

Page 24: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

JCheckBox Constructors

JCheckBox()JCheckBox()

JCheckBox(String text)JCheckBox(String text)

JCheckBox(String text, boolean selected)JCheckBox(String text, boolean selected)

JCheckBox(Icon icon)JCheckBox(Icon icon)

JCheckBox(String text, Icon icon)JCheckBox(String text, Icon icon)

JCheckBox(String text, Icon icon, boolean selected)JCheckBox(String text, Icon icon, boolean selected)

Page 25: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

JCheckBox Properties

JCheckBox has all the properties in JButton. JCheckBox has all the properties in JButton. Additionally, JButton has the following Additionally, JButton has the following property:property:

selectedselected

Page 26: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

JRadioButton

Radio buttons are variations of check Radio buttons are variations of check boxes. They are often used in the group, boxes. They are often used in the group, where only one button is checked at a time.where only one button is checked at a time.

Example 9.8: Using Radio ButtonsExample 9.8: Using Radio Buttons

RunRunRadioButtonDemoRadioButtonDemo

Page 27: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

JRadioButton Constructors

JRadioButton()JRadioButton()

JRadioButton(String text)JRadioButton(String text)

JRadioButton(String text, boolean selected)JRadioButton(String text, boolean selected)

JRadioButton(Icon icon)JRadioButton(Icon icon)

JRadioButton(String text, Icon icon)JRadioButton(String text, Icon icon)

JRadioButton(String text, Icon icon, boolean selected)JRadioButton(String text, Icon icon, boolean selected)

Page 28: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

JRadioButton Properties

JRadioButton has all the properties in JRadioButton has all the properties in JButton. Additionally, JButton has the JButton. Additionally, JButton has the following property:following property:

selectedselected

Page 29: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

Grouping Radio Buttons

ButtonGroup btg = new ButtonGroup();ButtonGroup btg = new ButtonGroup();

btg.add(jrb1);btg.add(jrb1);

btg.add(jrb2);btg.add(jrb2);

Page 30: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

Borders

You can set a border on any object of the You can set a border on any object of the JComponent class, but often it is useful to JComponent class, but often it is useful to set a titled border on a JPanel that groups a set a titled border on a JPanel that groups a set of related user interface components.set of related user interface components.

Example 9.9: Using BordersExample 9.9: Using Borders

RunRunBorderDemoBorderDemo

Page 31: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

Static Method for Creating BorderscreateTitledBorder(String title)createTitledBorder(String title)createLoweredBevelBorder()createLoweredBevelBorder()createRaisedBevelBorder()createRaisedBevelBorder()createLineBorder(Color color)createLineBorder(Color color)createLineBorder(Color color, int thickness)createLineBorder(Color color, int thickness)createEtchedBorder()createEtchedBorder()createEtchedBorder(Color highlight, Color shadow, createEtchedBorder(Color highlight, Color shadow, boolean selected)boolean selected)createEmptyBorder()createEmptyBorder()createMatteBorder(int top, int left, int bottom, int right, createMatteBorder(int top, int left, int bottom, int right, Icon tileIcon)Icon tileIcon)createCompoundBorder(Border outsideBorder, Border createCompoundBorder(Border outsideBorder, Border insideBorder)insideBorder)

Page 32: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

Message Dialogs

A A dialogdialog is normally used as a temporary is normally used as a temporary window to receive additional information window to receive additional information from the user, or to provide notification that from the user, or to provide notification that some event has occurred. some event has occurred.

Page 33: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

Creating Message Dialogs

Use static method inUse static method in JOptionPane JOptionPane class.class.

showMessageDialog(Component showMessageDialog(Component parentComponent, Object message, parentComponent, Object message, String title, int messageType)String title, int messageType)

showMessageDialog(Component showMessageDialog(Component parentComponent, Object message, parentComponent, Object message, String title, int messageType, Icon icon) String title, int messageType, Icon icon)

Page 34: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

Example 9.10: Using Message Dialogs Objective: Display student exam scores. The

program prompts the user to enter the user’s last name and the password in a dialog box. Upon receiving the correct user name and password, the program displays the student’s full name and the exam score.

RunRun

DialogDemoDialogDemo

Page 35: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

Menus Java provides several classes—Java provides several classes—JMenuBarJMenuBar, ,

JMenuJMenu, , JMenuItem, JCheckBoxMenuItem, JMenuItem, JCheckBoxMenuItem, andand JRadioButtonMenuItem JRadioButtonMenuItem —to implement menus —to implement menus in a frame.in a frame.

A JFrame or JApplet can hold a A JFrame or JApplet can hold a menu barmenu bar to to which the which the pull-down menuspull-down menus are attached. are attached. Menus consist of Menus consist of menu itemsmenu items that the user that the user can select (or toggle on or off). Menu bars can select (or toggle on or off). Menu bars can be viewed as a structure to support can be viewed as a structure to support menus.menus.

Page 36: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

Menu Demo

Page 37: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

The JMenuBar Class

JFrame f = new JFrame();JFrame f = new JFrame();f.setSize(300, 200);f.setSize(300, 200);f.setVisible(true);f.setVisible(true);JMenuBar mb = new JMenuBar(); JMenuBar mb = new JMenuBar(); f.setJMenuBar(mb);f.setJMenuBar(mb);

A menu bar holds menus; the menu bar can only be added to a frame. Following is the code to create and add a JMenuBar to a frame:

Page 38: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

The Menu Class

JMenu fileMenu = new JMenu("File", false);JMenu fileMenu = new JMenu("File", false);JMenu helpMenu = new JMenu("Help", true);JMenu helpMenu = new JMenu("Help", true);mb.add(fileMenu);mb.add(fileMenu);mb.add(helpMenu);mb.add(helpMenu);

You attach menus onto a JMenuBar. The following code creates two menus, File and Help, and adds them to the JMenuBar mb:

Page 39: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

The JMenuItem Class

fileMenu.add(new JMenuItem("new"));fileMenu.add(new JMenuItem("new"));fileMenu.add(new JMenuItem("open"));fileMenu.add(new JMenuItem("open"));fileMenu.add(new JMenuItem("-"));fileMenu.add(new JMenuItem("-"));fileMenu.add(new JMenuItem("print"));fileMenu.add(new JMenuItem("print"));fileMenu.add(new JMenuItem("exit"));fileMenu.add(new JMenuItem("exit"));fileMenu.add(new JMenuItem("-"));fileMenu.add(new JMenuItem("-"));

You add menu items on a menu. The following code adds menu items and item separators inmenu fileMenu:

Page 40: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

Submenus

JMenu softwareHelpSubMenu = new JMenu("Software");JMenu softwareHelpSubMenu = new JMenu("Software");

JMenu hardwareHelpSubMenu = new JMenu("Hardware");JMenu hardwareHelpSubMenu = new JMenu("Hardware");

helpMenu.add(softwareHelpSubMenu);helpMenu.add(softwareHelpSubMenu);

helpMenu.add(hardwareHelpSubMenu);helpMenu.add(hardwareHelpSubMenu);

softwareHelpSubMenu.add(new JMenuItem("Unix"));softwareHelpSubMenu.add(new JMenuItem("Unix"));

softwareHelpSubMenu.add(new JMenuItem("NT"));softwareHelpSubMenu.add(new JMenuItem("NT"));

softwareHelpSubMenu.add(new JMenuItem("Win95"));softwareHelpSubMenu.add(new JMenuItem("Win95"));

You can add submenus into menu items. The following code adds the submenus “Unix,” “NT,” and “Win95” into the menu item “Software.”

Page 41: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

Submenu Demo

Page 42: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

Example 9.11: Using Menus Objective: Create a user interface that Objective: Create a user interface that

performs arithmetic. The interface contains performs arithmetic. The interface contains labels and text fields for Number 1, Number labels and text fields for Number 1, Number 2, and Result. The Result box displays the 2, and Result. The Result box displays the result of the arithmetic operation between result of the arithmetic operation between Number 1 and Number 2.Number 1 and Number 2.

MenuDemoMenuDemo

RunRun

Page 43: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

Creating Multiple Windows

The following slides show step-by-step how The following slides show step-by-step how to create an additional window from an to create an additional window from an application or applet.application or applet.

Example 9.12: Creating Multiple WindowsExample 9.12: Creating Multiple Windows

RunRunMultipleWindowsDemoMultipleWindowsDemo

Page 44: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

Step 1: Create a subclass of JFrame (called a SubFrame) that tells the new window whatto do. For example, all the GUI application programs extend JFrame and are subclassesof JFrame.

Creating Additional Windows, Step 1

Page 45: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

Creating Additional Windows, Step 2

Step 2: Create an instance of Step 2: Create an instance of SubFrameSubFrame in in the application or applet.the application or applet.

Example:Example:

SubFrame subFrame = new SubFrame subFrame = new

SubFrame("SubFrame Title");SubFrame("SubFrame Title");

Page 46: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

Creating Additional Windows, Step 3

Step 3: Create a Step 3: Create a JButtonJButton for activating for activating the the subFramesubFrame..

add(new JButton("Activate SubFrame"));add(new JButton("Activate SubFrame"));

Page 47: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

Creating Additional Windows, Step 4

Step 4: Override the Step 4: Override the actionPerformed()actionPerformed()method as follows:method as follows:

public actionPerformed(ActionEvent e)public actionPerformed(ActionEvent e){ { String actionCommand = e.getActionCommand();String actionCommand = e.getActionCommand(); if (e.target instanceof Button)if (e.target instanceof Button) { { if ("Activate SubFrame".equals(actionCommand))if ("Activate SubFrame".equals(actionCommand)) { { subFrame.show();subFrame.show(); }} }}}}

Page 48: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

JScrollBar

A A scroll barscroll bar is a control that enables the is a control that enables the user to select from a range of values. user to select from a range of values. The scrollbar appears in two styles: The scrollbar appears in two styles: horizontalhorizontal and and verticalvertical..

Example 9.13: Using ScrollbarsExample 9.13: Using Scrollbars

ScrollBarDemoScrollBarDemo RunRun

Page 49: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

Scroll Bar Properties

Bubble

Unit increment

Block decrement Block increment

Minimal value Maximal value

Unit decrement

Page 50: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

JScrollPane

A scroll paneA scroll pane is a component that is a component that supports automatically scrolling without supports automatically scrolling without coding.coding.

Example 9.13: Using Scroll PanesExample 9.13: Using Scroll Panes

ScrollPaneDemoScrollPaneDemo RunRun

Page 51: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

Scroll Pane StructuresColumn headerCorner

Component

Row header

JViewport

Scrollable Component

Horizontal scroll bars

Vertical scroll bars

CornerComponent

CornerComponent

CornerComponent

Page 52: Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea

JTabbedPane

A tabbed pane A tabbed pane provides a set of provides a set of mutually exclusive tabs for accessing mutually exclusive tabs for accessing multiple components.multiple components.

Example 9.14: Using Tabbed PanesExample 9.14: Using Tabbed Panes

TabbedPaneDemoTabbedPaneDemo RunRun