?c 7y¨?? ? ) ?+BWB#FBO¥à Q ) 3ò?¨?? ?Fq ) ?¨?tFq7y?o Tm?¨?? ? ) 3 ?? P¨h?  )1¨?? ?Fq LCSP ¤ g What is a JavaBean? JavaBeanFq ^B?+ y¥ Java ?b JavaBean Fq? Java ?¥1" ?/m ? U ? JavaBean ? ?? ZE /ZE ¨ ?  a/ZE V? ? V[μ`ù ¥ZE V[μ?¨ZE K?1 p Vê1 p JComponent ?? )toolTipText4 UFq? ? )fontA Uó3 ?¨38 )background? ? )foreground -? ? )doubleBuffered ?? / ? )borderH  )preferredSizeFq j $ ¥ ?Xj )minimumSizeKlj )maximumSizeKvj JButton ? f ^B?? H(??1 Yq¥Fq .  Swing?? f?S JButtonb /ZE μ JButton() JButton(String text) JButton(String text, Icon icon) JButton(Icon icon) Example 9.1: Using Buttons RunButtonDemo JLabel S & ^A UBl ó3aB?m ?=? ¥μ¥ u× .Yè¨?ó  eFqFS &b S &¥/ZE : JLabel() JLabel(String text, int horizontalAlignment) JLabel(String text) JLabel(Icon icon) JLabel(Icon icon, int horizontalAlignment) Example 9.2: Using Labels RunLabelDemo JTextField ó'× ^B?4ó¨? { ?3?¥ { ? ub Example 9.3: Using Text Fields ' è LCó'× { ? ?3? add? f { 2Tb RunTextFieldDemo JTextArea ?TX ?¨? { ??ó3 P¨ó ' u ? LC . /ZE )JTextArea(int rows, int columns) 7yB?·?? ??  ?¥ó' ub )JTextArea(String s, int rows, int columns) 7yB?·?ó'a? ??  ?¥ó' ub Example 9.4 Using Text Areas )B?S &?A Um ? 6B?S &? A US5B?ó' u?A UB ó 3 . DescriptionPanel -jlblImage -jlblTitle -jtaTextDescription +setImageIcon +setTitle +setTextDescription +getMinimumSize 1 1 TextAreaDemo JPanel JFrame TextAreaDemo Run JComboBox F? 9?ê4  ^Bt[ "¥e ? V¨? ?V?é?ê4 ./ ZE ?/ JComboBox() Example 9.5: Using Combo Boxes RunComboBoxDemo JList V ¥T¨DF? 'M]? ? ? ] Hê4[ . Example 9.6: Using Lists ' è LC ?¨?ê4?SE ?a S &?A U ?êSES b RunListDemo JCheckBox ˉê  ^B?¨? ?u 7a1>ê[¥Fq ?]觥 71B" . Example 9.7: Using Check Boxes ' è LC?3?F?A U?b RunCheckBoxDemo JRadioButton ?ê? f ?¨?VBFê[?ê4·B¥B ?ê[ . Example 9.8: Using Radio Buttons RunRadioButtonDemo Borders H  ^ SwingFq¥?+ ?b V JComponent ?¥ ??`  !?B ?H  . Example 9.9: Using Borders RunBorderDemo Message Dialogs )? Yè¨T " H3 g¨ ?¤ l¨? ¥?F?4 U¨?? 3  t Yq . ) Example 9.10: Using Message Dialogs )'??¨?A UD 3 I k?¥?)b DialogDemo Run Menus ) Java 4 ???? ? — JMenuBar, JMenu, JMenuItem, JCheckBoxMenuItem, and JRadioButtonMenuItem. ) Java? LC???? – 7y?? £ – 7y?? – @F??[ – ??á 3 Yq 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 Run 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 window what to do. For example, all the GUI application programs extend JFrame and are subclasses of JFrame. Creating Additional Windows, Step 1 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 area. RunMultipleWindowsDemo 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 RunScrollBarDemo Scroll Bar Properties Bubble Unit increment Block decrement Block increment Minimal value Maximal value Unit decrement JScrollPane )A scroll pane is a component that supports automatically scrolling without coding. Example 9.14: Using Scroll Panes RunScrollPaneDemo Scroll Pane Structures Column headerCorner Component Row header JViewport Scrollable Component Horizontal scroll bars Vertical scroll bars Corner Component Corner Component Corner Component JTabbedPane )A tabbed pane provides a set of mutually exclusive tabs for accessing multiple components. Example 9.15: Using Tabbed Panes RunTabbedPaneDemo