Graphics in Java Dr. Andrew Wallace PhD BEng(hons) EurIng

Slides:



Advertisements
Similar presentations
Graphical User Interfaces
Advertisements

CS18000: Problem Solving and Object-Oriented Programming.
Graphic User Interfaces Layout Managers Event Handling.
Fall 2007CS 225 Graphical User Interfaces Event Handling Appendix C.
Event Driven Programming and GUIs Part 3 CS221 – 4/15/09.
Java GUI Libraries Swing Programming. Swing Components Swing is a collection of libraries that contains primitive widgets or controls used for designing.
Java Swing Toolkit Graphics The key to effectively using graphics in Java is understanding: –the basic components of the graphics library –the patterns.
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.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 14 GUI and Event-Driven Programming.
Creating a GUI with Swing. Introduction Very useful link: Swing – is a part of JFC (Java Foundation.
1 CMSC 132: Object-Oriented Programming II Nelson Padua-Perez William Pugh Department of Computer Science University of Maryland, College Park.
Object-Oriented Analysis and Design
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
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.
Contructing GUI’s in Java Implemented in the Swing API Imported into your programs by: import javax.swing.*; Most Swing programs also need the AWT packages.
GUI Programming in Java Tim McKenna GUI Programming Concepts l conventional programming: sequence of operations is determined by the program.
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.
Welcome to CIS 083 ! Events CIS 068.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
CSE 219 Computer Science III Graphical User Interface.
Object Oriented Programming Ders 11: Interfaces Mustafa Emre İlal
Java GUI CSCE 190 – Java Instructor: Joel Gompert Mon, July 26, 2004.
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.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
Field Trip #19 Animations with Java By Keith Lynn.
 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.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
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
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.
CompSci 100E 35.1 Graphical User Interfaces: GUIs  Components  Flat Layouts  Hierarchical Layouts  Designing a GUI  Coding a GUI.
CSE1030-HR GUI The Big Picture Building the View Building the Controller Separating the Concerns Going Further.
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.
 GUI – Graphic User Interface  Up to now in the programs we have written all output has been sent to the standard output device i.e.: the DOS console.
Lec.10 (Chapter 8 & 9) GUI Jiang (Jen) ZHENG June 27 th, 2005.
The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.
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.
CS 4244: Internet Programming User Interface Programming in Java 1.0.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Introduction to Java Chapter 9 - Graphical User Interfaces and Applets1 Chapter 9 Graphical User Interfaces and Applets.
1 Lecture 25 Listening to buttons and mice Quotes by Tony Hoare There are two ways of constructing a software design: (1) make it so simple that there.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Applets. 9/04/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L12: Applets Slide 2 Applets Usually.
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:
Introduction to Swing Mr. Crone. What is Swing? a collection of pre-made Java classes used to create a modern graphical user interface.
AWT Vs SWING. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many applications Uses.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
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
Graphical User Interfaces
Graphical User Interfaces -- GUIs
A First Look at GUI Applications
A Quick Java Swing Tutorial
Ellen Walker Hiram College
Course Outcomes of Advanced Java Programming AJP (17625, C603)
Steps to Creating a GUI Interface
A Quick Java Swing Tutorial
Presentation transcript:

Graphics in Java Dr. Andrew Wallace PhD BEng(hons) EurIng

Overview Events Graphics Swing Model – view – controller

Events Event driven Event handler Action Listener Component Display Event

Events State Event

Events State

Events switch(m_nState) { case STATE_A: handleStateA(); case STATE_B: handleStateB(); … }

Events private class MyEventListener implements ActionListener //add listener.addActionListener(this); public void actionPerformed(ActionEvent e) { … }

Events Multiple listeners per event Multiple events per listener Need to test for event source EventObject has method getSource which returns an Object

Events Design event listeners to be fast Minimise operations Execute in update thread Event types: Low level (mouse or key events) Semantic (all other events)

Events Not all interface events are of interest Adapters Implements listener’s methods with empty methods Inherited and use only those of interest Or use inner classes

Quiz What does an event signify in Java GUIs? How does event driven GUIs work?

Graphics AWT, Swing and JavaFX Abstract Windows Tool Kit Old version java.awt Swing Newer version More sophisticated javax.swing JavaFX Even newer!

Graphics Swing builds upon AWT public abstract class JComponent extends Container implements Serializable System independent Written in Java Executes in own thread Restrictions on updating screen Revalidate and repaint

Parts of Swing Containers JFrame (extends awt Frame) JPanel (extends JComponent) JScrollPane (extends JComponent) Components Jbutton JTextArea JMenu Containers

Parts of Swing Layout managers BoxLayout (swing) Allows for components to be laid out vertically or horizontally BoarderLayout (awt) North, south, east, west and centre GridLayout (awt) Grid squares with coords

Quiz How does swing differ from AWT? What are the two main parts of Swing?

Model – View - Controller Design method for GUIs Decouple data access / logic from display Model Data and rules View Display Controller Translate user input

Model – View - Controller Controller Model View UI events Change event Model change events

Model – View - Controller Implementation Viewer registers as a listener on the model Push model Model doesn’t know of the viewer (just broadcasts events) Bind the controller to the model User actions invoke controller methods

Model – View - Controller Controller ModelView

Model – View - Controller Implementation Viewer registers with the controller as a listener on the model Events sent through the controller Bind the controller to the model User actions invoke controller methods Increases the decoupling

Model – View - Controller public class MyModel extends AbstractModel { //Data //Reset model //Access methods }

Model – View - Controller public abstract class AbstractModel { protected PropertyChangeSupport m_PropChangSup; //add property change listener //remove property change listener //fire property change listener }

Model – View - Controller public abstract class AbstractController implements PropertyChangeListener { //arrays holding views and models //add / remove model //add / remove view //property change method to send event //set model property method }

Model – View - Controller Method method = model.getClass().getMethod(“set” + m_strPropertyName, new Class[] {newValue.getClass()}); method.invoke(model, newValue);

Model – View - Controller public class DefaultController extends AbstractController { //change element functions }

Model – View - Controller public class MyView extends view { //set the controller //model property change method //event handlers. Send events to controller }

Model – View - Controller Problem: Infinite loops Autonomous swing components can up date themselves Check values of update and current state

Quiz What does the parts of MVC do? How does MVC decouple objects?

Questions?