Graphical User Interfaces (Part 2) 1. View  view  presents the user with a sensory (visual, audio, haptic) representation of the model state  a user.

Slides:



Advertisements
Similar presentations
Event handling and listeners What is an event? user actions and context event sources and listeners Why should my programs be event- driven? User interaction.
Advertisements

Graphical User Interfaces (Part IV)
Fall 2007CS 225 Graphical User Interfaces Event Handling Appendix C.
A graphical user interface (GUI) is a pictorial interface to a program. A good GUI can make programs easier to use by providing them with a consistent.
Event Driven Programming and GUIs Part 3 CS221 – 4/15/09.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Event Handling Events and Listeners Timers and Animation.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 7 : Event-Driven Programming and GUI Objects.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Chapter 7 Event-Driven Programming and Basic GUI Objects.
GUI and Event-Driven Programming Recitation – 3/6/2009 CS 180 Department of Computer Science, Purdue University.
CPSC150 Week 12 Graphical User Interfaces Chapter 11.
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.
Advanced Java Class GUI, part 2. JComponent methods addXXXListener(XXXListener) repaint() – [optional arguments: delay and coordinates of sub-area to.
CPSC150 Week 12 Graphical User Interfaces Chapter 11.
More on Creating GUIs in Java using Swing David Meredith Aalborg University.
Chapter 6: Graphical User Interface (GUI) and Object-Oriented Design (OOD) J ava P rogramming: Program Design Including Data Structures Program Design.
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.
PROGRAMMING REVIEW Lab 2 EECS 448 Dr Fengjun Li and Meenakshi Mishra.
Java Programming Chapter 10 Graphical User Interfaces.
Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy
1 Event Driven Programming wirh Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Using the Netbeans GUI Builder. The Netbeans IDE provides a utility called the GUI Builder that assists you with creating Windows applications. The Netbeans.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Java GUI CSCE 190 – Java Instructor: Joel Gompert Mon, July 26, 2004.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
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.
FEN IntroJava2006 AAU1 GUI: Graphical User Interface AWT/SWING: Components Drag and Drop in NetBeans Events Listeners.
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.
CSE1030-HR GUI The Big Picture Building the View Building the Controller Separating the Concerns Going Further.
OOP (Java): GUI Intro/ OOP Objectives – –use an image viewer application to introduce Java's GUI features Semester 2,
CS-1020 Dr. Mark L. Hornick 1 Event-Driven Programming.
CS1054: Lecture 21 - Graphical User Interface. Graphical User Interfaces vs. Text User Interface.
Introduction to GUI in 1 Graphical User Interface 2 Nouf Almunyif.
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.
Swing - 2 Session 13. Swing - 2 / 2 of 38 Objectives (1) Discuss trees and tables Discuss progress bars Discuss MVC architecture Describe menus.
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.
Software Construction LAB 08 Java Programming with SWING GUI Builder.
1 Event Driven Programs with a Graphical User Interface Rick Mercer.
Chapter 14: Introduction to Swing Components. Objectives Understand Swing components Use the JFrame class Use the JLabel class Use a layout manager Extend.
Computer Science [3] Java Programming II - Laboratory Course Lab 4 -1 : Introduction to Graphical user interface GUI Components Faculty of Engineering.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
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.
1 Lecture 8: User Interface Components with Swing.
View  view  presents the user with a sensory (visual, audio, haptic) representation of the model state  a user interface element (the user interface.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Objects First With Java A Practical Introduction Using BlueJ Building Graphical User Interfaces (GUIs) Week
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.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
Java Programming Fifth Edition Chapter 13 Introduction to Swing Components.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
GUIs and Events Rick Mercer.
Inheritance (Part 4) Abstract Classes.
Graphical User Interfaces
A First Look at GUI Applications
Advanced User Interfaces
Graphical User Interface (pronounced "gooey")
Java Programming: From Problem Analysis to Program Design,
Ellen Walker Hiram College
Basic Elements of The GUI
Graphical User Interfaces in Java Event-driven programming
Presentation transcript:

Graphical User Interfaces (Part 2) 1

View  view  presents the user with a sensory (visual, audio, haptic) representation of the model state  a user interface element (the user interface for simple applications) 2

Simple Applications  simple applications often consist of just a single window (containing some controls) JFrame window with border, title, buttons 3

View as a Subclass of JFrame  a View can be implemented as a subclass of a JFrame  hundreds of inherited methods but only a dozen or so are commonly called by the implementer (see URL below) 4 View JFrame Frame Window Container Component Object user interface item holds other components plain window window with title and border

Implementing a View  the View is responsible for creating:  the Controller  all of the user interface (UI) components  menusJMenuBar, JMenu, JMenuItem  buttonsJButton  labelsJLabel  text fieldsJTextField  file dialogJFileChooser  the View is also responsible for setting up the communication of UI events to the Controller  each UI component needs to know what object it should send its events to 5

CalcView: Create Controller public class CalcView extends JFrame { public CalcView(CalcModel model) { super("Simple Calculator"); model.clear(); CalcController controller = new CalcController(model, this); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } 6

Menus  a menu appears in a menu bar (or a popup menu)  each item in the menu is a menu item 7 menu bar JMenuBar menu JMenu menu item JMenuItem JMenuBar + add(JMenu) JMenu + add(JMenuItem) JMenuItem **

Menus  to create a menu  create a JMenuBar  create one or more JMenu objects  add the JMenu objects to the JMenuBar  create one or more JMenuItem objectes  add the JMenuItem objects to the JMenu 8

Menus JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); menuBar.add(fileMenu); JMenuItem printMenuItem = new JMenuItem("Print"); fileMenu.add(printMenuItem); 9

CalcView: Menubar, Menu, Menu Items 10

Labels and Text Fields  a label displays unselectable text and images  a text field is a single line of editable text  the ability to edit the text can be turned on and off 11 label JLabel label JLabel text field (edit off) JTextField text field (edit on) JTextField

Labels  to create a label JLabel label = new JLabel("text for the label");  to create a text field (20 characters wide) JTextField textField = new JTextField(20); 12

CalcView: Labels and Text Fields 13

Buttons  a button responds to the user pointing and clicking the mouse on it (or the user pressing the Enter key when the button has the focus) 14 button JButton

Buttons  to create a button JButton button = new JButton("text for the button"); 15

CalcView: Buttons 16

File Chooser  a file chooser provides a GUI for selecting a file to open (read) or save (write) 17 file chooser (for choosing a file to open) JFileChooser

CalcView: File Chooser 18

Event Driven Programming  so far we have a View with some UI elements (buttons, text fields, menu items)  now we need to implement the actions  each UI element is a source of events  button pressed, slider moved, text changed (text field), etc.  when the user interacts with a UI element an event is triggered  this causes an event object to be sent to every object listening for that particular event  the event object carries information about the event  the event listeners respond to the event 19

Not a UML Diagram 20 event source 1 event source 2 event listener A event listener B event listener C event listener D event object 1 event object 2

Not a UML Diagram 21 "open" Controller event object "open" "save" "sum" "subtract" "multiply" "divide" "clear" event object "clear" AbstractButtonActionEvent implements ActionListener

Implementation  each JButton and JMenuItem has two inherited methods from AbstractButton public void addActionListener(ActionListener l) public void setActionCommand(String actionCommand)  for each JButton and JMenuItem 1. call addActionListener with the controller as the argument 2. call setActionCommand with a string describing what event has occurred 22

CalcView: Add Actions 23