GUI Programming in Java Tim McKenna GUI Programming Concepts l conventional programming: sequence of operations is determined by the program.

Slides:



Advertisements
Similar presentations
User Interface Design CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Advertisements

Fall 2007CS 225 Graphical User Interfaces Event Handling Appendix C.
Unit 091 Introduction to GUI Programming Introduction to User Interfaces Introduction to GUI Programming GUI Design Issues GUI Programming Issues Java.
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.
Lecture 15 Graphical User Interfaces (GUI’s). Objectives Provide a general set of concepts for GUI’s Layout manager GUI components GUI Design Guidelines.
Graphical User Interfaces (GUIs) GUI: An application that uses graphical objects to interact with users GUI applications consist of: –Events: A user or.
Creating a GUI with Swing. Introduction Very useful link: Swing – is a part of JFC (Java Foundation.
Unit 111 Java GUI Components and Events  Learning Outcomes oDistinguish between GUI components and containers. oIdentify and distinguish top-level containers.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Graphic User Interfaces Part 1. Typical GUI Screen from Microsoft Word What GUI “components” can you see? –Menus? Buttons? Labels? What else? –Anything.
PROGRAMMING REVIEW Lab 2 EECS 448 Dr Fengjun Li and Meenakshi Mishra.
Introduction to Java Swing “We are the sultans of swing” – Mark Knopfler.
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 
GUI Programming in Java
Java Programming Chapter 10 Graphical User Interfaces.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
Software Construction Lecture 10 Frameworks
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
Java Swing, Events and MVC Optional Readings: Eckel’s Thinking in Java: Chap 14 (
Applets and Frames CS 21a: Introduction to Computing I First Semester,
GUIs for Applets Introduction Applets and Swing/JFC Alternatives to Swing Look-and-Feel issues Example applet graphical user interfaces.
Object Oriented Programming Ders 11: Interfaces Mustafa Emre İlal
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 GUI CSCE 190 – Java Instructor: Joel Gompert Mon, July 26, 2004.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
GUI Chapter 10 Graphics context and objects Creating a window based application JFrame, JTextField, JButton Containers and Controls Graphics commands Layout.
Chapter 9: Visual Programming Basics Object-Oriented Program Development Using Java: A Class-Centered Approach.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
 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.
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.
CS Lecture 00 Swing overview and introduction Lynda Thomas
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.
SWING 101. IF YOU GET LOST - IMPORTANT LINKS  Swing articles:
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
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.
CS Fall 2012, Lab 09 Haohan Zhu. Boston University Slideshow Title Goes Here CS Fall 2012, Lab /20/2015 GUI - Graphical User Interface.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Week 6: Basic GUI Programming Concepts in Java Example: JFrameDemo.java container : a screen window/applet window/panel that groups and arranges components.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 – Graphical User Interfaces Java Foundations: Introduction to Programming.
Introduction to Java Chapter 9 - Graphical User Interfaces and Applets1 Chapter 9 Graphical User Interfaces and Applets.
Swing. Introduction to Swing What is Swing? “ Swing is a diverse collection of lightweight components that can be used to build sophisticated user interfaces.”
Basics of GUI Programming Chapter 11 and Chapter 22.
Creating a Window. A basic window in Java is represented by an object of the class Window in the package java.awt.
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.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Java Swing, Events Readings: Just Java 2: Chap 19 & 21, or Eckel’s Thinking in Java: Chap 14 Slide credits to CMPUT 301, Department of Computing Science.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
1 Lecture 8: User Interface Components with Swing.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
Introduction to Swing Mr. Crone. What is Swing? a collection of pre-made Java classes used to create a modern graphical user interface.
Chapter 6 Building Java GUIs. MVC Model View Controller The model passes its data to the view for rendering The view determines which events are passed.
Java Swing What is swing? Swing is a ”Lightweight” GUI ToolKit for Java Different from AWT / SWT Toolkits for GUIs Few lines of code to produce GUI elements.
A Quick Java Swing Tutorial
A First Look at GUI Applications
Java GUI.
Ellen Walker Hiram College
Event Driven Programming and Graphical User Interface
Basic Elements of The GUI
Week 8 Swing NetBeans GUI Builder
Advanced Programming in Java
Advanced GUIs and Graphics
Graphical User Interface
TA: Nouf Al-Harbi NoufNaief.net :::
Presentation transcript:

GUI Programming in Java Tim McKenna

GUI Programming Concepts l conventional programming: sequence of operations is determined by the program what you want to happen, happens when you want it l event-driven programming: sequence of operations is determined by the user’s interaction with the application’s interface anything that can happen, happens at any time

GUI Design Concepts l a wealth of information creates a poverty of attention - Herbert Simon l Principles of good GUI Design Principles of good GUI Design l IBM's Design conceptsDesign concepts l Saul Greenberg's HCI pagesHCI pages l Tim's HCI notesHCI notes

GUI Programming Concepts in Java l Java GUI ("Swing") has components l Windows GUI has controls l Unix GUI has widgets examples: labels, buttons, check boxes, radio buttons, text input boxes, pull down lists Java Swing components: JLabel, JButton, JCheckBox, JRadioButton, JTextField, JTextArea, JComboBox

Java GUI history: the AWT l AWT(JDK 1.0, 1.1): Abstract Window Toolkit l package: java.awt, java.awt.event l heavyweight components using native GUI system elements l used for applets until most browsers supported JRE 1.2

Swing in Java l Swing(Java 2, JDK 1.2+) l lightweight components that do not rely on the native GUI or OS l “look and feel” of Swing components are identical on different platforms can be customized l Swing inherits from AWT l AWT still used for events, layouts

Swing Components in Java l advanced GUI support. e.g. drag-and-drop l package names: javax.swing, javax.swing.event l components inherit from JComponent l components are added to a top-level container: JFrame, JDialog, or JApplet.

running a Swing application l java -Dswing.aatext=true MySwingClass the option sets the system property "swing.aatext" to "true" to enable anti- aliasing for every JComponent javaw runs a GUI without the console window l e.g. HelloWorldSwing.java

Basic GUI Programming Steps in Java l declare a container and components l add components to one or more containers using a layout manager l register event listener(s) with the components l create event listener method(s)

Basic GUI Programming Concepts in Java Example: JFrameDemoTM.java, JFrameDemoTM2.java, JFrameDemo.java container : a screen window/applet window/panel that groups and arranges GUI components GUI component: an object with visual representation Swing containers: JFrame, JApplet, JPanel AWT containers: Frame, Applet, Panel

GUI Programming: The Java Approach l event-driven programming a piece of code (i.e. event handler ) is attached to a GUI component an event handler is called when an event (e.g. a mouse click) is activated / fired l The Delegation Event Model in Java processing of an event is delegated to an object (the listener) in the program

Event-driven Programming in Java event source: a GUI component that generates / fires an event event: a user interaction (e.g. a click on the button) event listener: an object that has implemented event handlers to react to an event

Event Handling in Java l the delegation event model - event listeners must be registered with an event source in order to receive notification

Event Handling in Java registration of an event listener - write a class that implements an [ event type]Listener interface - create an instance of that class (i.e. an event listener) - register the listener with a GUI component: add[event type]Listener ( )

Event Handling in Java l a listener interface has a list of standard event handlers (i.e. methods) API documentation - java.awt.event - event classes - listener interfaces - adapter classes

Event Handling in Java l different ways of coding the event listeners l JFrameDemoTM.java uses named inner classes. l JFrameDemoTM2.java uses named inner classes and shows how to consolidate window closing from two different events. l JFrameDemo.java does not use inner classes.