Download presentation
Presentation is loading. Please wait.
1
Java GUI programming with Swing
Tim McKenna
2
Java 2 Swing Components Java Foundation Classes(JFC) - Java 2 Swing components - Java2D graphics classes the class JComponent(API) Swing Tutorial Swing Connection
3
Swing Components button: JButton label: JLabel
item selection: JCheckBox, JRadioButton, JToggleButton object selection: JComboBox, JList, JSpinner text: JTextField, JTextArea, JEditorPane, JFormattedTextField, JPasswordField menus: JMenuBar, JMenu, JMenuItem, ...
4
Swing Components and Events
Event Source Event Type Generated JButton ActionEvent JTextField ActionEvent (but don't listen for it) JMenuItem ActionEvent JComboBox ItemEvent, ActionEvent JCheckBox ItemEvent JRadioButton ItemEvent (but don't listen for it) JList ListSelectionEvent
5
Swing Components Example(Online Reservation): Reservation.java
Swing Components: JRadioButton, JCheckBox, JComboBox, JTextField, JButton, JPanel Event Handling JRadioButton, JCheckBox: addItemListener( ) ItemListener interface: itemStateChanged( ) ItemEvent: getStateChange( )
6
Swing Components Event Handling JComboBox: addActionListener( ), getSelectedItem( ), getSelectedIndex( ) JTextField: addActionListener( ) ActionEvent: getActionCommand( )
7
Swing Components Example: JListDemo.java.
Swing Components: JList, JButton Event Handling JList: addListSelectionListener(), getSelectedIndex(), getSelectedIndices() ListSelectionListener interface: valueChanged() javax.swing.event.ListSelectionEvent
8
Swing Components Example: JTextDemo.java Swing Components: JTextField, JTextArea, JButton Event Handling: JTextField: addActionListener( ) vs. getText( ) JTextArea: NO listener is registered! append( ), insert( ), setText( ), getSelectedText( ), getText( )
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.