What is a JavaBean? JavaBean Java JavaBean Java JavaBean
JComponent tooltiptext font background foreground doublebuffered border preferredsize minimumsize maximumsize
JButton. Swing JButton JButton() JButton(String text) JButton(String text, Icon icon) JButton(Icon icon) Example 9.1: Using Buttons ButtonDemo
JLabel. : JLabel() JLabel(String text, int horizontalalignment) JLabel(String text) JLabel(Icon icon) JLabel(Icon icon, int horizontalalignment) Example 9.2: Using Labels LabelDemo
JTextField Example 9.3: Using Text Fields add TextFieldDemo
JTextArea. JTextArea(int rows, int columns) JTextArea(String s, int rows, int columns)
Example 9.4 Using Text Areas. JPanel JFrame DescriptionPanel 1 1 TextAreaDemo -jlblimage -jlbltitle -jtatextdescription +setimageicon +settitle +settextdescription +getminimumsize TextAreaDemo
JComboBox. JComboBox() Example 9.5: Using Combo Boxes ComboBoxDemo
JList. Example 9.6: Using Lists ListDemo
JCheckBox. Example 9.7: Using Check Boxes CheckBoxDemo
JRadioButton. Example 9.8: Using Radio Buttons RadioButtonDemo
Borders Swing JComponent. Example 9.9: Using Borders BorderDemo
Message Dialogs. Example 9.10: Using Message Dialogs DialogDemo
Menus Java JMenuBar, JMenu, JMenuItem, JCheckBoxMenuItem, and JRadioButtonMenuItem. Java
Example 9.11: Using Menus Objective: Create a user interface that performs arithmetic. The interface contains labels and text fields for Number 1, Number 2, and Result. The Result box displays the result of the arithmetic operation between Number 1 and Number 2. MenuDemo
Creating Multiple Windows The following slides show step-by-step how to create an additional window from an application or applet.
Creating Additional Windows, Step 1 Step 1: Create a subclass of JFrame (called a SubFrame) that tells the new window what to do. For example, all the GUI application programs extend JFrame and are subclasses of JFrame.
Creating Additional Windows, Step 2 Step 2: Create an instance of SubFrame in the application or applet. Example: SubFrame subframe = new SubFrame("SubFrame Title");
Creating Additional Windows, Step 3 Step 3: Create a JButton for activating the subframe. add(new JButton("Activate SubFrame"));
Creating Additional Windows, Step 4 Step 4: Override the actionperformed() method as follows: public actionperformed(actionevent e) { String actioncommand = e.getactioncommand(); if (e.target instanceof Button) { if ("Activate SubFrame".equals(actionCommand)) { subframe.setvisible(true); } } }
Example 9.12 Creating Multiple Windows This example creates a main window with a text area in the scroll pane, and a 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 MultipleWindowsDemo area. Histogram
JScrollBar A scroll bar is a control that enables the user to select from a range of values. The scrollbar appears in two styles: horizontal and vertical. Example 9.13: Using Scrollbars ScrollBarDemo
Scroll Bar Properties Minimal value Block decrement Block increment Maximal value Bubble Unit decrement Unit increment
JScrollPane A scroll pane is a component that supports automatically scrolling without coding. Example 9.14: Using Scroll Panes ScrollPaneDemo
Scroll Pane Structures Corner Component Column header Corner Component JViewport Row header Scrollable Component Vertical scroll bars Corner Component Corner Component Horizontal scroll bars
JTabbedPane A tabbed pane provides a set of mutually exclusive tabs for accessing multiple components. Example 9.15: Using Tabbed Panes TabbedPaneDemo