Graphical User Interfaces

Slides:



Advertisements
Similar presentations
1 Graphical User Interface (GUI) Applications Abstract Windowing Toolkit (AWT) Events Handling Applets.
Advertisements

Drawing in a frame – Java GUI
Graphic User Interfaces Layout Managers Event Handling.
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.
Fall 2007CS 225 Graphical User Interfaces Event Handling Appendix C.
Java Swing Recitation – 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University.
Event-Driven Programming Thus far, our programs have been executed one statement after the other However, many programs depend on user actions to dictate.
1 Chapter 7 Graphics and Event Handling. 2 Overview The java.awt and javax.swing packages and their subpackages support graphics and event handling. Many.
Java GUI Libraries Swing Programming. Swing Components Swing is a collection of libraries that contains primitive widgets or controls used for designing.
Swing CS-328 Dick Steflik John Margulies. Swing vs AWT AWT is Java’s original set of classes for building GUIs Uses peer components of the OS; heavyweight.
GUI and Event-Driven Programming Recitation – 3/6/2009 CS 180 Department of Computer Science, Purdue University.
Creating a GUI with Swing. Introduction Very useful link: Swing – is a part of JFC (Java Foundation.
CS221 © 2007 Ray S. Babcock Event-Driven Programming Appendix C.
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.
CPSC150 Week 12 Graphical User Interfaces Chapter 11.
GUI Programming in Java Tim McKenna GUI Programming Concepts l conventional programming: sequence of operations is determined by the program.
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.
A.k.a. GUI’s.  If you want to discuss your Lab 2 grade come see me this week. ◦ Office: 436 ERB. One hour prior to class ◦ Open to Appointments MWF 
Java Programming Chapter 10 Graphical User Interfaces.
Design Patterns and Graphical User Interfaces Horstmann ,
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
CSE 219 Computer Science III Graphical User Interface.
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.
Java GUIs and Graphics CNS Outline  Introduction  Events  Components  Layout managers  Drawing  Introduction  Events  Components  Layout.
עקרונות תכנות מונחה עצמים תרגול 4 - GUI. Outline  Introduction to GUI  Swing  Basic components  Event handling.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
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 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
– Advanced Programming P ROGRAMMING IN Lecture 21 Introduction to Swing.
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.
GUI Clients 1 Enterprise Applications CE00465-M Clients with Graphical User Interfaces.
MSc Workshop - © S. Kamin, U. ReddyLect 3 - GUI -1 Lecture 3 - Graphical User Interfaces r GUI toolkits in Java API r JFrame r GUI components.
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.
ITEC 109 Lecture 27 GUI. GUIs Review Sounds –Arrays hold sample values –Creating a keyboard –Sound effects Homework 3 –The big two –Due after break –Lab.
CS Fall 2012, Lab 09 Haohan Zhu. Boston University Slideshow Title Goes Here CS Fall 2012, Lab /20/2015 GUI - Graphical User Interface.
CS1054: Lecture 21 - Graphical User Interface. Graphical User Interfaces vs. Text User Interface.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
CS 4244: Internet Programming User Interface Programming in Java 1.0.
Review_6 AWT, Swing, ActionListener, and Graphics.
Basics of GUI Programming Chapter 11 and Chapter 22.
Graphical User Interfaces Tonga Institute of Higher Education.
Java Programming, Second Edition Chapter Thirteen Understanding Swing Components.
1 Layout Managers Layout managers –Provided for arranging GUI components –Provide basic layout capabilities –Processes layout details –Programmer can concentrate.
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.
Lesson 28: More on the GUI button, frame and actions.
Graphical User Interface (GUI)
1 Lecture 8: User Interface Components with Swing.
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
MIT AITI 2004 Swing Event Model Lecture 17. The Java Event Model In the last lecture, we learned how to construct a GUI to present information to the.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
Java Swing and Events Chris North cs3724: HCI. Presentations nadine edwards, steve terhar Vote: UI Hall of Fame/Shame?
1 A Quick Java Swing Tutorial. 2 Introduction Swing – A set of GUI classes –Part of the Java's standard library –Much better than the previous library:
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 7 Event-Driven Programming and Basic GUI Objects.
A Quick Java Swing Tutorial
Introduction Many Java application use a graphical user interface or GUI (pronounced “gooey”). A GUI is a graphical window or windows that provide interaction.
Graphical User Interfaces
A First Look at GUI Applications
Graphical User Interface (pronounced "gooey")
A Quick Java Swing Tutorial
Ellen Walker Hiram College
Course Outcomes of Advanced Java Programming AJP (17625, C603)
Design Patterns in Swing and AWT
Design Patterns in Swing and AWT
Timer class and inner classes
A Quick Java Swing Tutorial
Graphical User Interface
Presentation transcript:

Graphical User Interfaces User interaction problem: User can spontaneously change the value (state) of a user interface object x (e.g., a check box or scrollbar), often called the subject You want a set of observer objects o1, o2, ... — not necessarily GUI objects — to “know about” every change in x’s value Other (non-GUI) situations are similar Solution: ???

Solution #1: Use Polling x o1 o1 Each observer continually (periodically, occasionally) polls the subject to ask if its state has changed Inefficient, cumbersome...

Solution #2: Use Events x x event o1 Each observer goes about its own business, until the subject tells it that its value has changed

Implementing Solution #2: The Observer Pattern Subject expects each observer to register with the subject to indicate its interest in subject’s events Subject keeps track of this (dynamic) set of interested observers When its state changes, subject calls a specific callback method of each registered observer, passing as parameter an event object that describes the state change

Example: Simple GUI Demo interface that any observer of a subject that is a JButton object must implement actionPerformed is the callback method <<interface>> ActionListener + actionPerformed (ActionEvent e) a DemoFrame object in GUIDemo_1 is the observer (it implements ActionListener) a frame is a window on the screen that acts as a container for GUI objects (aka GUI components) a JButton object in DemoFrame is the subject (its events are of interest) JFrame GUIDemo_1 DemoFrame … + actionPerformed (ActionEvent e) DemoFrame JButton holds a reference to a DemoFrame object

A Little More Detail call this method from main to make sure program can be stopped! JFrame … + setDefaultCloseAction (int operation) + show ( ) + getContentPane ( ) : Container + pack ( ) <<interface>> ActionListener + actionPerformed (ActionEvent e) call this method from main to display the frame (window) on the screen call this method from DemoFrame to get the content pane that contains the frame’s GUI components call this method from DemoFrame to organize the GUI components in the frame’s content pane using the layout manager you’ve selected call this method from DemoFrame to add an observer for any subject that is a JButton object DemoFrame … + actionPerformed (ActionEvent e) JButton … + addActionListener (ActionListener o)

This Specific Case of the Observer Pattern A JButton object (the subject) expects each observer to call addActionListener to indicate interest in that JButton’s events Each JButton object keeps track of its own set of ActionListener objects When its state changes, a JButton object calls actionPerformed on each registered ActionListener object, passing as a parameter an ActionEvent object

Java GUI Fundamentals JFrame JTextArea JPanel JButton This is a simple sample application that uses most (if not all) the fatures you’ll need for the calculator application JButton

Java GUI Packages java.awt java.awt.event javax.swing ... These are the main packages for GUI stuff There are others, but these should be the primary places where you should look in the documentation when you need information

Basic Java GUI Widgets (Swing) All in package javax.swing: JFrame JPanel JButton JTextArea JScrollPane ... Use widgets starting with J from the swing library They are more portable, nicer looking, and more powerful than AWT widgets

Layout Managers A layout manager allows you to arrange components inside panels without providing specific coordinates of widgets In packages java.awt, javax.swing: FlowLayout (default for JPanel) BorderLayout (default for JFrame content pane) GridLayout ... Briefly describe each of those listed drawing pictures to explain the difference in how they arrange components