Timer class and inner classes

Slides:



Advertisements
Similar presentations
Graphic User Interfaces Layout Managers Event Handling.
Advertisements

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Outline Graphics Applets Drawing Shapes Components and Containers Images.
Corresponds with Chapter 12
Event Driven Programming and GUIs Part 3 CS221 – 4/15/09.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Chapter 5: Keyboard I/O & Simple GUI’s Copyright 2002, Matthew Evett. These slides are based on slides copyrighted by John Lewis and William Loftus, 2002,
Lecture 15 Graphical User Interfaces (GUI’s). Objectives Provide a general set of concepts for GUI’s Layout manager GUI components GUI Design Guidelines.
Chapter Day 10. © 2007 Pearson Addison-Wesley. All rights reserved4-2 Agenda Day 10 Questions from last Class?? Problem set 2 posted  10 programs from.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
ITEC220 GUI Lecture – Part 1 References  Java Software Solutions,” by Lewis & Loftus  Chapter 3  Chapter 4  Chapter 5  Chapter 6  Java Foundations-Introduction.
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.
Chapter Day 9. © 2007 Pearson Addison-Wesley. All rights reserved4-2 Agenda Day 8 Questions from last Class?? Problem set 2 posted  10 programs from.
Chapter 6: Graphical User Interface (GUI) and Object-Oriented Design (OOD) J ava P rogramming: Program Design Including Data Structures Program Design.
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 Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
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.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
GUI Components and Design Here we add one more component to our programs, JButtons –JButtons can only be inserted into JPanels (or JApplets) –Clicking.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
 2002 Prentice Hall, Inc. All rights reserved Introduction Graphical User Interface (GUI) –Gives program distinctive “look” and “feel” –Provides.
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.
1 Graphical User Interfaces AWT and Swing packages Frames and Panels Components Nested Panels Images Reading for this Lecture: L&L, 3.9 – 3.11.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
Timer class and inner classes. Processing timer events Timer is part of javax.swing helps manage activity over time Use it to set up a timer to generate.
Object Oriented programming Instructor: Dr. Essam H. Houssein.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Layout Managers Arranges and lays out the GUI components on a container.
GUI Basics. What is GUI? A graphical user interface (GUI) is a type of user interface item that allows people to interact with programs in more ways than.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 – Graphical User Interfaces Java Foundations: Introduction to Programming.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Java Programming: From Problem Analysis to Program Design, Second Edition1 Lecture 5 Objectives  Learn about basic GUI components.  Explore how the GUI.
Basics of GUI Programming Chapter 11 and Chapter 22.
Graphical User Interfaces A Graphical User Interface (GUI) in Java is created with at least three kinds of objects: –components, events, and listeners.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
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)
Event Handler Methods Text field Object Responder JAVA AWT Environment: Messages are sent between JAVA Objects Screen Event Notification Press Button.
1 Lecture 8: User Interface Components with Swing.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
A Quick Java Swing Tutorial
Graphical User Interfaces
Chapter 9: Graphical User Interfaces
Christopher Budo, Davis Nygren, spencer franks, Luke miller
A First Look at GUI Applications
Processing Timer Events
Java GUI.
Graphical User Interface (pronounced "gooey")
Java Programming: From Problem Analysis to Program Design,
Ellen Walker Hiram College
Chap 7. Building Java Graphical User Interfaces
Layout Managers A layout manager is an object that determines the way that components are arranged in a container There are several predefined layout managers.
Chapter 13: Advanced GUIs and Graphics
Graphical User Interfaces -- Introduction
Containers and Components
Creating Graphical User Interfaces
Advanced Programming in Java
GUI building with the AWT
Advanced GUIs and Graphics
Graphical User Interface
TA: Nouf Al-Harbi NoufNaief.net :::
TA: Nouf Al-Harbi NoufNaief.net :::
Presentation transcript:

Timer class and inner classes

Processing timer events is part of javax.swing helps manage activity over time Use it to set up a timer to generate an action event periodically When a timer event takes place, timer calls actionPerformed(ActionEvent event) part of the ActionListener interface (java.awt.event) Example: TimerTester.java

Inner classes Inner class Any class defined inside another is available to all the methods of the enclosing class Can access the members of the enclosing class Can reference the outer class using (Outerclass.this)

Anonymous inner classes Anonymous classes Often encountered within a method Combines the creation of an object with the definition Requires the inclusion of a semi-colon marking the end of expression containing the anonymous class Objects defined inside the method but outside of class Must be final before used inside anonymous class

GUI-based Applications

Graphical Applications Java apps having graphical components Called GUI components GUI component An object representing a screen element Some are containers used to hold other components GUI related classes Defined in java.awt and javax.swing packages

GUI Containers Frame Panel Used to display GUI-based Java application Displayed as a window with a title bar A heavyweight container Managed by the underlying operating system Panel Container that is not stand-alone Must be added to another container to be displayed Used to organize other components Lightweight container managed by the java program itself

Example: Authority Label Let us look at a program GUI component displaying a line of text Used to display information or to identify other components Let us look at a program Organizing two labels in a panel And displaying panel in a frame

Layout Management An object Several predefined managers That determines the way components Are arranged in a container Several predefined managers Are provided by Java standard class library Three useful layout managers: Flow Layout Border Layout Grid Layout

Border Layout This manager groups container Into five areas: center, north, west, south and east Default manager for a frame To use it in a panel: panel.setLayout(new BorderLayout()); When adding a component: panel.add(component, BorderLayout.NORTH);

Grid Layout This manager groups components into a grid with a fixed number of rows and columns Adds the components, row by row, left to right JPanel numberPanel = new JPanel(); numberPanel.setLayout(new GridLayout(4, 3)); numberPanel.add(button7); numberPanel.add(button8); numberPanel.add(button9); numberPanel.add(button4); . . .

GUI Interfaces GUI revolves around Event Listener Components Events Listeners Event Represents some activity to which we may want to respond May be generated by a graphical component Listener Defines what happens when an event occurs

A corresponding listener Events and Listeners Event Component A component object may generate an event Listener A corresponding listener object is designed to respond to the event When the event occurs, the component calls the appropriate method of the listener, passing an object that describes the event © 2004 Pearson Addison-Wesley. All rights reserved

Example: PushCounter A push button The pushcounter example Allows the user to initiate an action By pressing a graphical button using the mouse is defined by JButton class The pushcounter example Displays a push button Increments a counter each time a button is pushed

Determining Event Sources One listener Can be used to listen to two different components In this case, The source of the event can be determined by Using the getSource method of the event received by listener Example label + two buttons With label indicating which of the 2 buttons is pressed

Example: TextFields A text field Fahrenheit.java Allows the user to enter one line of input Generates an event when the enter key is pressed Fahrenheit.java Instantiates a listener and adds it to text field When user enters temperature in Fahrenheit The conversion into Celsius is performed

Simple GUI-based Input/Output with JOptionPane Most applications use windows or dialog boxes To interact with the user JOptionPane provides prebuilt dialog boxes for input/output, displayed via static methods: showInputDialog Displays an input dialog that collects input data from user showMessageDialog Displays an output message dialog to the user showConfirmDialog Displays a dialog box with a yes/no question to the user

Icon Types

Image Icons

Images Images are often used in a program with a graphical interface As we have seen, a JLabel object can be used To display a line of text It can also be used to display an image That is, a label can be composed of text, and image Or both at the same time

Images (Cont’d) The ImageIcon class Can be used to represent an image that is stored in a label The position of the text relative to the image Can be set explicitly The alignment of text and image within label Can be set as well Refer to ImageIconDemo project