Graphical User Interface (pronounced "gooey")

Slides:



Advertisements
Similar presentations
1 Event Listeners Some Events and Their Associated Event Listeners Act that Results in the EventListener Type User clicks a button, presses Enter while.
Advertisements

Basic Java – Interface design. Understand: How to use TextPad for Java How to define classes and objects How to create a GUI interface How event-driven.
Graphical User Interfaces Java’s AWT and Swing APIs.
Examples. // A simple Frame with Rectangle Inside import java.awt.*; import javax.swing.*; import java.awt.geom.*; // For Shapes class rectComponent extends.
Drawing in a frame – Java GUI
CS18000: Problem Solving and Object-Oriented Programming.
Unit 3 Graphical User Interface (GUI) Dr. Magdi AMER.
Graphic User Interfaces Layout Managers Event Handling.
F27SB2 Programming Languages
Graphical User Interfaces, 2D Graphics & Game Programming.
CMSC 341 Building Java GUIs. 09/26/2007 CMSC 341 GUI 2 Why Java GUI Development? Course is about Data Structures, not GUIs. We are giving you the opportunity.
Things to mention public static void main(String [] args) –The starting point for a free-standing Java application (i.e. one not run from the DrJava interactions.
Introduction to Java Classes, events, GUI’s. Understand: How to use TextPad How to define a class or object How to create a GUI interface How event-driven.
Java Swing Recitation – 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University.
Event Driven Programming and GUIs Part 3 CS221 – 4/15/09.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
GUI and Event-Driven Programming Recitation – 3/6/2009 CS 180 Department of Computer Science, Purdue University.
Chapter 121 Window Interfaces Using Swing Chapter 12.
CS102--Object Oriented Programming Lecture 19: – The Swing Package (II) Copyright © 2008 Xiaoyan Li.
©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, 2006 Chapter 10 Graphics and event- driven programs.
Scott Grissom, copyright 2006Ch 11: GUI Slide 1 Graphical User Interfaces (Ch 11) Careful design of a graphical user interface is key to a viable software.
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.
CPSC150 Week 12 Graphical User Interfaces Chapter 11.
1 Class 8. 2 Chapter Objectives Use Swing components to build the GUI for a Swing program Implement an ActionListener to handle events Add interface components.
Java Programming Chapter 10 Graphical User Interfaces.
Introduction to GUI Java offers a great number of pre-defined classes to support the development of graphical user interfaces –These are broken down into.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Introduction to GUI in Java 1. Graphical User Interface Java is equipped with many powerful,easy to use GUI component such as input and output dialog.
MIT AITI 2003 Lecture 17. Swing - Part II. The Java Event Model Up until now, we have focused on GUI's to present information (with one exception) Up.
GUI Components and Design Here we add one more component to our programs, JButtons –JButtons can only be inserted into JPanels (or JApplets) –Clicking.
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
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.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary Litvin, and Skylight.
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Introduction to GUI in 1 Graphical User Interface 2 Nouf Almunyif.
Introduction to Java Chapter 9 - Graphical User Interfaces and Applets1 Chapter 9 Graphical User Interfaces and Applets.
Review_6 AWT, Swing, ActionListener, and Graphics.
Ajmer Singh PGT(IP) JAVA IDE Programming - I. Ajmer Singh PGT(IP) GUI (Graphical User Interface) It is an interface that uses a graphic entities along.
Java Programming, Second Edition Chapter Thirteen Understanding Swing Components.
Chapter 14: Introduction to Swing Components. Objectives Understand Swing components Use the JFrame class Use the JLabel class Use a layout manager Extend.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
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,
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
Graphical User Interface (GUI)
View  view  presents the user with a sensory (visual, audio, haptic) representation of the model state  a user interface element (the user interface.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
Java Programming Fifth Edition Chapter 13 Introduction to Swing Components.
GUIs & Event-Driven Programming Chapter 11 Review.
Introduction Many Java application use a graphical user interface or GUI (pronounced “gooey”). A GUI is a graphical window or windows that provide interaction.
A First Look at GUI Applications
Java GUI.
Java Swing.
Graphical User Interface (GUI) Programming III
Ellen Walker Hiram College
MSIS670: Object-Oriented Software Engineering
Timer class and inner classes
Basic Elements of The GUI
IFS410: Advanced Analysis and Design
Window Interfaces Using Swing Objects Chapter 12
Window Interfaces Using Swing Objects Chapter 12
CiS 260: App Dev I Chapter 6: GUI and OOD.
Graphical User Interface
Presentation transcript:

Graphical User Interface (pronounced "gooey") 7/19/2018 7:40 PM Chapter 11 GUI Graphical User Interface (pronounced "gooey") Typically used with applications written for Windows or OSX Event-driven, responding to events such as a mouse click Refer to page 275 in the text. © 2007 Lawrenceville Press

Chapter 11 Creating a Swing GUI 7/19/2018 7:40 PM Chapter 11 Creating a Swing GUI A GUI must begin with a top-level container, such as a frame, for holding a content frame A content frame, such as a panel, holds and displays components and gets added to a container Components include labels Refer to page 275 in the text. © 2007 Lawrenceville Press

frame panel label Chapter 11 A Swing GUI 7/19/2018 7:40 PM Chapter 11 A Swing GUI frame panel label Note: This slide contains animations. Press the space bar or click the mouse button to display each animation. This slide contains four (4) animations. Refer to pages 275 through 277 in the text. A frame is a container, which is a window with a border, title, and buttons for minimizing, maximizing, and closing the frame. <press space bar> A panel is a content frame, which can hold and display components. <press space bar> A label is a component that displays text. Components must be placed in a content frame to be displayed in a container. <press space bar> © 2007 Lawrenceville Press

Chapter 11 The JFrame Class 7/19/2018 7:40 PM Chapter 11 The JFrame Class Part of the java.swing package The JFrame class is used to create a frame for a GUI JFrame methods include: setDefaultLookAndFeelDecorated() setDefaultCloseOperation() getContentPane() setContentPane() pack() setVisible() Refer to page 276 in the text. © 2007 Lawrenceville Press

Chapter 11 The JPanel Class 7/19/2018 7:40 PM Chapter 11 The JPanel Class Part of the java.swing package The JPanel class is used to create a content frame for a GUI JPanel methods include: add() remove() Refer to page 276 in the text. © 2007 Lawrenceville Press

Chapter 11 The JLabel Class 7/19/2018 7:40 PM Chapter 11 The JLabel Class Part of the java.swing package The JLabel class is used to create an object for displaying text JLabel constructors and methods include: JLabel() setText() Refer to page 277 in the text. © 2007 Lawrenceville Press

Chapter 11 The JButton Class 7/19/2018 7:40 PM Chapter 11 The JButton Class Part of the java.swing package The JButton class is used to create an object that can be clicked by the user. Provides a means of communication between the user and the interface. Requires a listener object to determine when the user has clicked the button JButton constructors and methods include: JLabel() setActionCommand() getActionCommand() addActionListener() Refer to page 278 in the text. © 2007 Lawrenceville Press

Chapter 11 Handling Events 7/19/2018 7:40 PM Chapter 11 Handling Events A listener object responds to an event by executing an event handler named actionPerformed() The actionPerformed() method has a parameter for the action command string, which is passed by the event The component requiring a listener must set the action command and add an action listener The class containing a listener must implement the ActionListener interface Refer to pages 279 and 280 in the text. © 2007 Lawrenceville Press

Chapter 11 Component Layout 7/19/2018 7:40 PM Chapter 11 Component Layout FlowLayout manager places components one next to the other in a row BoxLayout manager places components one after the other in a column GridLayout manager places components into a grid of rows and columns Borders and alignment can be changed to control layout within a layout manager Refer to pages 281 and 284 in the text. © 2007 Lawrenceville Press

Chapter 11 The JTextField Class 7/19/2018 7:40 PM Chapter 11 The JTextField Class Part of the java.swing package The JTextField class is used to create an object where users can enter data JTextField constructors and methods include: JTextField() getText() addActionListener() Refer to page 285 in the text. © 2007 Lawrenceville Press

Chapter 11 Processing Numeric Data 7/19/2018 7:40 PM Chapter 11 Processing Numeric Data Data typed into a text field is a string Class methods in the Double and Integer classes can be used to convert string data to numeric data and the reverse Double class methods include: parseDouble() toString() Integer class methods include: parseInteger() toString() Refer to pages 285 and 286 in the text. © 2007 Lawrenceville Press

Chapter 11 The JComboBox Class 7/19/2018 7:40 PM Chapter 11 The JComboBox Class Part of the java.swing package The JComboBox class is used to create an object where users select a choice from a list of choices JComboBox constructors and methods include: JComboBox() setSelectedIndex() getSelectedItem() setEditable() addActionListener() Refer to page 288 in the text. © 2007 Lawrenceville Press

7/19/2018 7:40 PM Chapter 11 Adding Color Swing Components have methods for changing their colors: setBackground() setForeground() The methods for changing color require a parameter from the Color class How the color changes varies between components Refer to page 291 in the text. © 2007 Lawrenceville Press

Chapter 11 Adding Images to Applications 7/19/2018 7:40 PM Chapter 11 Adding Images to Applications Many Swing components support images GIF and JPG image formats work best The JLabel and JButton classes include the setIcon() method for adding an image to a component The JLabel and JButton constructors may also specify an image Refer to pages 292 and 293 in the text. © 2007 Lawrenceville Press

Chapter 11 Nested Classes 7/19/2018 7:40 PM Chapter 11 Nested Classes A class within a class is called a nested class Nested classes are members of the class they are within The class containing the nested class is called the outer class Refer to page 295 in the text. © 2007 Lawrenceville Press

outer class nested class Chapter 11 A Nested Class 7/19/2018 7:40 PM Chapter 11 A Nested Class outer class public class MyApp { outer class data members outer class constructors and methods class MyListener implements ActionListener { public void actionPerformed(ActionEvent event) { … } } } nested class Note: This slide contains animations. Press the space bar or click the mouse button to display each animation. This slide contains two (2) animations. Refer to page 295 in the text. A class that contains a class member is called an outer class. <press space bar> A class member within a class is called the nested class. <press space bar> © 2007 Lawrenceville Press