Dale Roberts GUI Programming using Java - GUI Components Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.

Slides:



Advertisements
Similar presentations
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 17 Creating User Interfaces.
Advertisements

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.
1 Chapter 8 Objects and Classes Lecture 2 Prepared by Muhanad Alkhalisy.
Dale Roberts GUI Programming using Java - Mouse Events Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
1 Chapter 13 Creating User Interfaces. 2 Objectives F To create graphical user interfaces with various user-interface components: JButton, JCheckBox,
 2005 Pearson Education, Inc. All rights reserved GUI Components: Part 1.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 16 Creating User Interfaces.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 15 Creating User.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L03 (Chapter 15) Creating.
1 Creating User Interfaces. 2 Motivations A graphical user interface (GUI) makes a system user-friendly and easy to use. Creating a GUI requires creativity.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Graphical User Interface Components: Part 1
Dale Roberts Object Oriented Programming using Java - Class Constructors Dale Roberts, Lecturer Computer Science, IUPUI Department.
PROGRAMMING REVIEW Lab 2 EECS 448 Dr Fengjun Li and Meenakshi Mishra.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
GUI Programming in Java: Event Handling & More Components Corresponds with Chapter 14, Chapter 15.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 16.1 Test-Driving the Flag Quiz Application.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 13 Creating User.
Dale Roberts Introduction to Java - Access Specifiers Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
Dale Roberts Object Oriented Programming using Java - Enumerations Dale Roberts, Lecturer Computer Science, IUPUI Department.
Dale Roberts GUI Programming using Java - Event Handling Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
Dale Roberts Program Control using Java - Selection Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
Graphical User Interface Components: Part 1 Chapter 11.
Java Swing. Swing is a set of classes that provides more powerful and flexible components than are possible with the AWT. In addition to the familiar.
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.
Dale Roberts Object Oriented Programming using Java - OOD to OOP: ATM Case Study Dale Roberts, Lecturer Computer Science, IUPUI
GUI Programming using NetBeans. RHS – SOC 2 GUI construction We have previously talked about elements in a (simple) GUI –Frames, Panes and Dialogs –Text.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 15 Creating User.
CS-1020 Dr. Mark L. Hornick 1 Event-Driven Programming.
Dale Roberts Object Oriented Programming using Java - Final and Static Keywords Dale Roberts, Lecturer Computer Science, IUPUI
Introduction to Java Chapter 9 - Graphical User Interfaces and Applets1 Chapter 9 Graphical User Interfaces and Applets.
Graphical User Interface Components: Part 1 Chapter 11.
Creating User Interfaces Chapter 13 CSCI CSCI 1302 – Creating User Interfaces2 Outline Introduction Common Features of Swing GUI Components Buttons.
Creating User Interfaces Event-Driven Programming.
COSC 3461 S04 Module 3 Widgets. 2 Outline What is a widget? Buttons Combo boxes Text components Message boxes.
Java Programming, Second Edition Chapter Thirteen Understanding Swing Components.
Copyright © Curt Hill More Widgets In Abstract Window Toolbox.
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.
 Figure illustrates a hierarchy containing many event classes from the package java.awt.event.  Used with both AWT and Swing components.  Additional.
Java Swing Controls. JButton One of the most commonly used swing component is Push Button or simply button which is created through JButton class of Swing.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 17.1 Test-Driving the Student Grades Application.
1 Lecture 8: User Interface Components with Swing.
Dale Roberts Object Oriented Programming using Java - Getters and Setters Dale Roberts, Lecturer Computer Science, IUPUI
Jozef Goetz Credits: Copyright  Pearson Education, Inc. All rights reserved. expanded by J. Goetz, 2016.
Notes for Assignment #2 Assn2: GUI Database Interface Corresponds with Chapters 28, 29, 31.
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.
Dale Roberts GUI Programming using Java - Windowing Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
© Copyright by Pearson Education, Inc. All Rights Reserved. Appendix I GUI Components and Event Handling Android How to Program, 3/e.
GUI Programming using Java - Event Handling
CSC 205 Programming II Lecture 5 AWT - I.
JButton Chapter 11 Lecture 3.
11 GUI Components: Part 1.
A First Look at GUI Applications Radio Buttons and Check Boxes
GUI Programming using Java - Key Events
11 GUI Components: Part 1.
Appendix I GUI Components and Event Handling
Advanced User Interfaces
Graphical User Interface (GUI) Components: Part 1 Java How to Program, 9 th Edition Chapter 14.
Chapter 7 Creating User Interfaces
Chapter 13 Creating User Interfaces
GUI Programming using Java - Mouse Events
Chapter 17 Creating User Interfaces
Chapter 17 Creating User Interfaces
Java GUI programming with Swing
Presentation transcript:

Dale Roberts GUI Programming using Java - GUI Components Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School of Science, IUPUI

Dale Roberts 2 JButton Abstract Button Component user clicks to trigger a specific action Can be command button, check box, toggle button or radio button Button types are subclasses of class AbstractButton

Dale Roberts 3 JButton Command button Generates an ActionEvent when it is clicked Created with class JButton Text on the face of the button is called button label

Dale Roberts 4Outline ButtonFram e.java (1 of 2) Declare two JButton instance variables Create new JButton Create two ImageIcon sCreate new JButton Set rollover icon for JButton

Dale Roberts 5Outline ButtonFram e.java (2 of 2) Create handler for buttons Register event handlers Inner class implements ActionListener Access outer class’s instance using this reference Get text of JButton pressed

Dale Roberts 6Outline ButtonTest. java (1 of 2)

Dale Roberts 7Outline Button Test.ja va (2 of 2)

Dale Roberts 8 JButton JButton s can have a rollover icon Appears when mouse is positioned over a button Added to a JButton with method setRolloverIcon

Dale Roberts 9 Software Engineering Observation 11.4 When used in an inner class, keyword this refers to the current inner-class object being manipulated. An inner- class method can use its outer-class object’s this by preceding this with the outer-class name and a dot, as in ButtonFrame.this.

Dale Roberts 10 Buttons That Maintain State State buttons Swing contains three types of state buttons JToggleButton, JCheckBox and JRadioButton JCheckBox and JRadioButton are subclasses of JToggleButton

Dale Roberts 11 JCheckBox JCheckBox Contains a check box label that appears to right of check box by default Generates an ItemEvent when it is clicked ItemEvent s are handled by an ItemListener Passed to method itemStateChanged Method isSelected returns whether check box is selected ( true ) or not ( false )

Dale Roberts 12Outline CheckBoxF rame.java (1 of 3) Declare two JCheckBox instance variables Set font of text field

Dale Roberts 13Outline CheckBoxF rame.java (2 of 3) Create two JCheckBox es Create event handlerRegister event handler with JCheckBox es Inner class implements ItemListener itemStateChanged method is called when a JCheckBox is clicked Test whether JCheckBox is selected

Dale Roberts 14Outline CheckBoxF rame.java (3 of 3) Test source of the event isSelected method returns whether JCheckBox is selected

Dale Roberts 15Outline CheckBoxT est.java

Dale Roberts 16 JRadioButton JRadioButton Has two states – selected and unselected Normally appear in a group in which only one radio button can be selected at once Group maintained by a ButtonGroup object Declares method add to add a JRadioButton to group Usually represents mutually exclusive options

Dale Roberts 17Outline RadioButto nFrame.jav a (1 of 3) Declare four JRadioButton s and a ButtonGroup to manage them

Dale Roberts 18Outline RadioButto nFrame.java (2 of 3) Create the four JRadioButton s Create the ButtonGroup Add each JRadioButton to the ButtonGroup

Dale Roberts 19Outline RadioButto nFrame.java (3 of 3) Register an event handler with each JRadioButton Event handler inner class implements ItemListener When radio button is selected, the text field’s font will be set to the value passed to the constructor

Dale Roberts 20Outline RadioButto nTest.java

Dale Roberts 21 JComboBox and Using an Anonymous Inner Class for Event Handling Combo box Also called a drop-down list Implemented by class JComboBox Each item in the list has an index setMaximumRowCount sets the maximum number of rows shown at once JComboBox provides a scrollbar and up and down arrows to traverse list

Dale Roberts 22 Using an Anonymous Inner Class for Event Handling Anonymous inner class Special form of inner class Declared without a name Typically appears inside a method call Has limited access to local variables

Dale Roberts 23Outline ComboBox Frame.java (1 of 2) Declare JComboBox instance variable

Dale Roberts 24Outline ComboBox rame.java (2 of 2) Create JComboBox and set maximum row count Create anonymous inner class as the event handler Declare method itemStateChanged Method getSelectedIndex locates selected item Test state change of JComboBox

Dale Roberts 25Outline ComboBox Test.java Scrollbar to scroll through the items in the list scroll arrowsscroll box

Dale Roberts 26 JList List Displays a series of items from which the user may select one or more items Implemented by class JList Allows for single-selection lists or multiple-selection lists A ListSelectionEvent occurs when an item is selected Handled by a ListSelectionListener and passed to method valueChanged

Dale Roberts 27Outline ListFrame.j ava (1 of 2) Declare JList instance variable

Dale Roberts 28Outline ListFrame.j ava (2 of 2) Create JList Set selection mode of JList Add JList to ScrollPane and add to application Get index of selected item

Dale Roberts 29Outline ListTest.jav a

Dale Roberts 30 Multiple-Selection Lists Multiple-selection list Enables users to select many items Single interval selection allows only a continuous range of items Multiple interval selection allows any set of elements to be selected

Dale Roberts 31Outline Multiple SelectionFr ame.java (1 of 3)

Dale Roberts 32Outline Multiple SelectionFr ame.java (2 of 3) Use a multiple interval selection list Use methods setListData and getSelectedValues to copy values from one JList to the other

Dale Roberts 33Outline Multiple SelectionFr ame.java (3 of 3) Set cell width for presentationSet cell height for presentation Set selection model to single interval selection

Dale Roberts 34Outline Multiple SelectionTe st.java

Dale Roberts Acknowledgements Deitel, Java How to Program