CSE1030-HR GUI The Big Picture Building the View Building the Controller Separating the Concerns Going Further.

Slides:



Advertisements
Similar presentations
15 Copyright © 2005, Oracle. All rights reserved. Adding User Interface Components and Event Handling.
Advertisements

Graphical User Interfaces (Part IV)
Fall 2007CS 225 Graphical User Interfaces Event Handling Appendix C.
 What are the basic GUI components we’ve learned so far? › JFrame › JPanel › JButton › JLabel › JTextArea › JTextField › JCheckBox › JRadioButton › Paint.
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.
Event Handling Events and Listeners Timers and Animation.
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.
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.
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.
GUI Programming in Java Tim McKenna GUI Programming Concepts l conventional programming: sequence of operations is determined by the program.
More on Creating GUIs in Java using Swing David Meredith Aalborg University.
CC1007NI: Further Programming Week 5 Dhruba Sen Module Leader (Islington College)
Graphic User Interfaces Part 1. Typical GUI Screen from Microsoft Word What GUI “components” can you see? –Menus? Buttons? Labels? What else? –Anything.
GUI Programming in Java
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
Draw Shapes Introduction to simple graphics. What is a Component? A class that resides in the java.awt package Examples include: –Button, java.awt.Button.
1 Event Driven Programming wirh Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Java the UML Way versjon Only to be used in connection with the book "Java the UML Way", by Else Lervik and.
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 (
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 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.
Introduction to Swing Components Chapter 14.  Part of the Java Foundation Classes (JFC)  Provides a rich set of GUI components  Used to create a Java.
GUI Chapter 10 Graphics context and objects Creating a window based application JFrame, JTextField, JButton Containers and Controls Graphics commands Layout.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
– 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.
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.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Concurrent Programming and Threads Threads Blocking a User Interface.
SWING 101. IF YOU GET LOST - IMPORTANT LINKS  Swing articles:
Graphical User Interfaces (Part 2) 1. View  view  presents the user with a sensory (visual, audio, haptic) representation of the model state  a user.
CS Fall 2012, Lab 09 Haohan Zhu. Boston University Slideshow Title Goes Here CS Fall 2012, Lab /20/2015 GUI - Graphical User Interface.
Software Design 5.1 From Using to Programming GUIs l Extend model of "keep it simple" in code to GUI  Bells and whistles ok, but easy to use and hide.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Graphics in Java Dr. Andrew Wallace PhD BEng(hons) EurIng
GUI DYNAMICS Lecture 11 CS2110 – Fall GUI Statics and GUI Dynamics  Statics: what’s drawn on the screen  Components buttons, labels, lists, sliders,
5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise.
The Swing GUI Components Chapter 29 An enhanced alternative to AWT The PC does not need an appletviewer or browser Swing overcomes some AWT drawbacks.
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.
Computer Science [3] Java Programming II - Laboratory Course Lab 4 -1 : Introduction to Graphical user interface GUI Components Faculty of Engineering.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 15 : Swing III King Fahd University of Petroleum & Minerals College of Computer.
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.
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.
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:
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.
GUI 1: JFC and Swing Basics OOP tirgul No
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
A Quick Java Swing Tutorial
Ellen Walker Hiram College
Course Outcomes of Advanced Java Programming AJP (17625, C603)
Event Driven Programming and Graphical User Interface
A Quick Java Swing Tutorial
Presentation transcript:

CSE1030-HR GUI The Big Picture Building the View Building the Controller Separating the Concerns Going Further

CSE1030-HR The BIG Picture…

CSE1030-HR 1.The user launches an app This is just the usual main-method class. 2.The app creates a view object The view object appears as a window with some components on it. It runs in a separate thread. 3.The user interacts with the view E.g. by typing in or clicking on a component. 4.The component notifies the controller E.g. by saying: “the user clicked on me!” 5.The controller informs the model and the view The model is queried or updated. The view is changed in response to what the user did.

CSE1030-HR App Controller Model View instantiates launches interacts updates The Objects

CSE1030-HR The View…

CSE1030-HR The Epitome of Delegation Low-Level Pixel-level manipulations in the java.awt classes. E.g. the shape drawing done in CSE1020. High-Level Component-level visualizations in javax.swing. Application-Level Use swing components as building blocks to assemble the view. Building a view is quite complex if done at the pixel level. The complexity is confronted by an elaborate delegation scheme that relies heavily on inheritance and aggregation.

CSE1030-HR The Building Blocks  MenuBar Frame File View    OK My name is…  Select Component Layout Manager

CSE1030-HR The Building Blocks  MenuBar Frame File View    OK My name is…  Select Component Layout Manager

CSE1030-HR The Building Blocks  MenuBar Frame File View    OK My name is…  Select Component Layout Manager My age is…

CSE1030-HR The Building Blocks  MenuBar Frame File View    OK My name is…  Select Component Layout Manager My age is…

CSE1030-HR 1 * JComponent JMenuBar add(JMenu) JMenu add(JMenuItem) JFrame add(Component) setLayout(LayoutManager) setJMenuBar(JMenuBar) JMenuItem * * By combining “is-a” with “has-a”, we nest menus! Layout- Manager 1

CSE1030-HR Example

CSE1030-HR Overview of the View Landscape Components: JButton JLabel JList, JComboBox, JTable, JTree JPanel JCheckBox, JRadioButton JScrollPane, JSplitPane JTextComponent JTextField, JTextArea, JPasswordField, JEditorPane Layout Managers: Flow, Border, Grid, Card, … We cover only a small subset. See: java.sun.com/docs/books/tutorial

CSE1030-HR The Controller…

CSE1030-HR Events: the Timeline The End User - Clicks on a button or menu: Action event - Mouse, Key, Window, … event The O/S - Determines the window to receive the event - Informs it of the event’s details The window’s Frame - Determines (based on the layout manager) which component (if any) is at the event’s location - Informs it of the event’s details The Component - Notifies all its registered listeners

CSE1030-HR To become an action listener on button: 1.Write a class Controller that implements ActionListener 2.Implement the method public void actionPerformed(ActionEvent) 3.The View instantiates Controller Controller controller = new Controller(); 4.The View registers controller with button: button.addActionListener(controller); Whenever the user clicks the button, actionPerformed will be invoked with the Event as argument. It should consult the Model and update the View if needed.

CSE1030-HR Example

CSE1030-HR Separating the Concerns…

CSE1030-HR One “ugly” Extreme All three agents (the view, model, and controller) are in one class. All have access to the “private” attributes. Very hard to debug runtime errors due to entanglement and size. Almost impossible to debug logic errors exposed via testing if different people wrote different parts. Programmers working on the view see (and can modify) business logic (the model). Business rules cannot be reused in a second application.

CSE1030-HR The other extreme Separate classes for the MVC agents Separate Controller class per event Need public accessors to enable the controller to update the view (e.g. change font of a component) The model is reusable Lends itself to multithreading Note: We can relax the 2 nd requirement (i.e. use only one controller class) by using setActionCommand(String) and getActionCommand().

CSE1030-HR In between… Controller is an inner class of View Can have one controller or one per event Controller has easy access to the private attributes of View, and hence, can easily update the view.

CSE1030-HR Example

CSE1030-HR Going Further… This material is optional

CSE1030-HR Going Further Menus - Mnemonics & Accelerator (see KeyEvent/Stroke) - JMenuItem and JButton extend AbstractButton MVC - Assistive Technologies; see tutorial - JSF, JSP, Struts, … Multithreading - The Event Dispatch Thread and thread safety - Threading event handlers and invokeLater Applets - Extend JApplet (see Ch. 18) Graphics (start with 1020 graphics)

CSE1030-HR JComponent paintComponent(Graphics) getWidth(): int getHeight(): int Graphics2D getColor(): Color getFont(): Font getStroke(): Stroke setColor(Color) setFont(Font) setStroke(Stroke) 1 The Aggregation Hierarchy (CSE1020) UniPanel in 1020

CSE1030-HR The Aggregation Hierarchy (CSE1020)