Java GUI programming with Swing Tim McKenna

Slides:



Advertisements
Similar presentations
Chapter 16 GUI Programming Basics GUI Overview Event-Driven Programming Basics GUI Classes and Packages A Simple Window Program JFrame Class Java Components.
Advertisements

15 Copyright © 2005, Oracle. All rights reserved. Adding User Interface Components and Event Handling.
Advance Java Technology Java’s Role::MVC Architecture :: Swing Prof.Chintan Dave.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 17 Creating User Interfaces.
Chapter 11 Creating User Interfaces F What is JavaBean? F JComponent F JButton  ImageIcon  JLabel  JTextField  JTextArea  JComboBox  JList  JCheckBox.
More on GUI We wrap up our examination of Java GUI programming by looking at several other components and their listeners – The components all come from.
Drawing in a frame – Java GUI
TCU CoSc Programming with Java Handling Events.
Fall 2007CS 225 Graphical User Interfaces Event Handling Appendix C.
Event Handling Events and Listeners Timers and Animation.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 14 GUI and Event-Driven Programming.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 14 GUI and Event-Driven Programming.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 14 GUI and Event-Driven Programming.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 14 GUI and Event-Driven Programming.
GUI and Event-Driven Programming Part 2. Event Handling An action involving a GUI object, such as clicking a button, is called an event. The mechanism.
Advanced Java Class GUI, part 2. JComponent methods addXXXListener(XXXListener) repaint() – [optional arguments: delay and coordinates of sub-area to.
Graphical User Interface Components: Part 1
GUI Programming in Java Tim McKenna GUI Programming Concepts l conventional programming: sequence of operations is determined by the program.
PROGRAMMING REVIEW Lab 2 EECS 448 Dr Fengjun Li and Meenakshi Mishra.
GUI Programming in Java: Event Handling & More Components Corresponds with Chapter 14, Chapter 15.
Creating User Interfaces F JComponent F JButton F JLabel F JTextField F JTextArea F JComboBox F JList F JCheckBox F JRadioButton F Dialogs.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Java GUIs and Graphics CNS Outline  Introduction  Events  Components  Layout managers  Drawing  Introduction  Events  Components  Layout.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
Graphical User Interface in Java
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Graphical User Interface Components: Part 1 Chapter 11.
SWING. AbstractButton Swing Buttons are subclasses of the AbstractButton class, which extends JComponent. Abstract class javax.swing.AbstractButton AbstractButton.
1 Outline 1 Introduction 2 Overview of Swing Components 3 JLabel 4 Event Handling 5 TextFields 6 How Event Handling Works 7 JButton 8 JCheckBox and JRadioButton.
Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary Litvin, and Skylight.
Dale Roberts GUI Programming using Java - GUI Components Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
SE-1021 Software Engineering II Week 5, Class 1 Learning Resources From inner classes to anonymous Inner Classes Additional GUI components Inheritance.
CSE1030-HR GUI The Big Picture Building the View Building the Controller Separating the Concerns Going Further.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 15 Creating User.
CS1054: Lecture 21 - Graphical User Interface. Graphical User Interfaces vs. Text User Interface.
Swing / Session1 / 1 of 30 Module Introduction Distributed Computing in Java.
Java GUI. Overview The ”idea” The ”idea” The Components The Components Listeners Listeners The Program The Program Interface Eventlistener Interface Eventlistener.
Swing Components. Introduction Swing – A set of GUI classes – Part of the Java's standard library –Much better than the previous library: AWT Abstract.
The Swing GUI Components Chapter 29 An enhanced alternative to AWT The PC does not need an appletviewer or browser Swing overcomes some AWT drawbacks.
Graphical User Interface Components: Part 1 Chapter 11.
Software Construction LAB 08 Java Programming with SWING GUI Builder.
Copyright © Curt Hill More Widgets In Abstract Window Toolbox.
1 Event Driven Programs with a Graphical User Interface Rick Mercer.
Chapter 14: Introduction to Swing Components. Objectives Understand Swing components Use the JFrame class Use the JLabel class Use a layout manager Extend.
Computer Science [3] Java Programming II - Laboratory Course Lab 4 -1 : Introduction to Graphical user interface GUI Components Faculty of Engineering.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 15 : Swing III King Fahd University of Petroleum & Minerals College of Computer.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
Lecture 33: More Graphical User Interface (GUI) Announcements & Review Read Ch GU1 & GU2 Cohoon & Davidson Ch 14 Reges & Stepp Lab 10 set game due 4/26.
 Figure illustrates a hierarchy containing many event classes from the package java.awt.event.  Used with both AWT and Swing components.  Additional.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Introduction to GUI in 1 Graphical User Interface 3 Nouf Almunyif.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
TENTH LECTURE Event and listener. Events and Listeners An event can be defined as a type of signal to the program that something has happened. The event.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
Java Programming Fifth Edition Chapter 13 Introduction to Swing Components.
Dept. of CSIE, National University of Tainan 10/21/2012 Responding to User Input.
GUIs and Events Rick Mercer.
Christopher Budo, Davis Nygren, spencer franks, Luke miller
Appendix I GUI Components and Event Handling
Graphical User Interface (pronounced "gooey")
Graphical user interface with Swing by jose maria gonzalez pinto
Graphical User Interface (GUI) Components: Part 1 Java How to Program, 9 th Edition Chapter 14.
Ellen Walker Hiram College
Chapter 13: Advanced GUIs and Graphics
Basic Elements of The GUI
IFS410: Advanced Analysis and Design
Chapter 17 Creating User Interfaces
Chapter 17 Creating User Interfaces
Advanced GUIs and Graphics
Java GUI programming with Swing
Presentation transcript:

Java GUI programming with Swing Tim McKenna

Java 2 Swing Components l Java Foundation Classes(JFC) - Java 2 Swing components - Java2D graphics classes l the class JComponent(API) l l Swing Tutorial Swing Tutorial l Swing Connection Swing Connection

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,...

Swing Components and Events Event SourceEvent Type Generated JButtonActionEvent JTextFieldActionEvent (but don't listen for it) JMenuItemActionEvent JComboBoxItemEvent, ActionEvent JCheckBoxItemEvent JRadioButtonItemEvent (but don't listen for it) JListListSelectionEvent

Swing Components l Example(Online Reservation): Reservation.java – listens to everything ReservationTM.java – listens when it matters l a key point is WHEN components should be listened to. l components often do not need a listener l components can be inspected for their state: JTextField.getText() JRadioButton.isSelected() JCheckBox.isSelected() JComboBox.getSelectedIndex()

Swing Components Event Handling JRadioButton, JCheckBox: addItemListener( ) ItemListener interface: itemStateChanged( ) ItemEvent: getStateChange( )

Swing Components Event Handling JComboBox: addActionListener( ), getSelectedItem( ), getSelectedIndex( ) JTextField: addActionListener( ) ActionEvent: getActionCommand( )

Swing Components l Swing Component: JListJList l Example: JListDemo.java l Inspect JList: getSelectedIndex() - returns -1 if there is no selection. getSelectedIndices() - empty array if nothing is selected getSelectedValue() – returns null or object referred to in the list isSelectionEmpty() l Event Handling: addListSelectionListener() javax.swing.event.ListSelectionListener interface valueChanged()

Swing Components Example: JTextDemo.java Swing Components: JTextField, JTextArea, JButton l Event Handling: l JTextField: addActionListener( ) vs. getText( ) l JTextArea: NO listener is registered! append( ), insert( ), setText( ), getSelectedText( ), getText( )