Java GUI programming with Swing

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.
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.
Graphical User Interfaces (GUIs) GUI: An application that uses graphical objects to interact with users GUI applications consist of: –Events: A user or.
©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
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.
Object Oriented Programming Ders 11: Interfaces Mustafa Emre İlal
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,
(c) by Elizabeth Sugar Boese.1 Chapter 12 Events on Components - Lecture Slides.
Graphical User Interface in Java
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Graphical User Interface Components: Part 1 Chapter 11.
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.
CS Fall 2012, Lab 09 Haohan Zhu. Boston University Slideshow Title Goes Here CS Fall 2012, Lab /20/2015 GUI - Graphical User Interface.
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.
DCS2133 Object Oriented Programming Graphical User Interface & Event-Driven Programming.
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.
5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise.
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.
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.
 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.
1 Lecture 8: User Interface Components with Swing.
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.
Java GUI programming with Swing Tim McKenna
GUIs and Events Rick Mercer.
Christopher Budo, Davis Nygren, spencer franks, Luke miller
11 GUI Components: Part 1.
Advanced User Interfaces
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.
Chapter 13: Advanced GUIs and Graphics
Basic Elements of The GUI
IFS410: Advanced Analysis and Design
Advanced GUIs and Graphics
Graphical User Interface
Presentation transcript:

Java GUI programming with Swing Tim McKenna Seneca@York

Java 2 Swing Components Java Foundation Classes(JFC) - Java 2 Swing components - Java2D graphics classes the class JComponent(API) http://java.sun.com/products/jfc Swing Tutorial 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 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

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( )

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

Swing Components Example: JListDemo.java. Swing Components: JList, JButton Event Handling JList: addListSelectionListener(), getSelectedIndex(), getSelectedIndices() ListSelectionListener interface: valueChanged() javax.swing.event.ListSelectionEvent

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( )