Review: Java GUI Programming

Slides:



Advertisements
Similar presentations
TCU CoSc Programming with Java Handling Events.
Advertisements

Java GUI Libraries Swing Programming. Swing Components Swing is a collection of libraries that contains primitive widgets or controls used for designing.
June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 1 Lecture 9 Object Oriented Programming in Java Advanced Topics Abstract Windowing.
Java Swing Toolkit Graphics The key to effectively using graphics in Java is understanding: –the basic components of the graphics library –the patterns.
Event Handling Events and Listeners Timers and Animation.
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.
GUI Programming in Java Tim McKenna GUI Programming Concepts l conventional programming: sequence of operations is determined by the program.
Java Swing Chris North cs3724: HCI. AWT to Swing AWT: Abstract Windowing Toolkit import java.awt.* Swing: new with Java2 import javax.swing.* Extends.
Introduction to Java Swing “We are the sultans of swing” – Mark Knopfler.
GUI Programming in Java
ACM/JETT Workshop - August 4-5, ExceptionHandling and User Interfaces (Event Delegation, Inner classes) using Swing.
Software Construction Lecture 10 Frameworks
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.
עקרונות תכנות מונחה עצמים תרגול 4 - GUI. Outline  Introduction to GUI  Swing  Basic components  Event handling.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
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 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.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
An Introduction to Programming and Object Oriented Design using Java 3 rd Edition. Dec 2007 Jaime Niño Frederick Hosch Chapter 18 Integrating user interface.
CS GUI Frameworks CS 3331 Fall CS 3331 Outline MVC Model GUI components (widgets) Layout managers Handling events.
Frameworks CompSci 230 S Software Construction.
CS Fall 2012, Lab 09 Haohan Zhu. Boston University Slideshow Title Goes Here CS Fall 2012, Lab /20/2015 GUI - Graphical User Interface.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 13. Review Shared Data Software Architectures – Black board Style architecture.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
CompSci Event Handling. CompSci Event Handling The Plan  Sequential (Single Thread) Model  Event Model  Making the GUI interactive  Examples.
Object Oriented Programming.  Interface  Event Handling.
Model View Controller (MVC) Bigger than a Pattern: It’s an Architecture Rick Mercer with help from many of others 1.
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.
Object-Oriented Application Frameworks CS 3331 Sections 8.1 & 8.3 of [Jia 03]
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.
Graphical User Interface (GUI)
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:
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 7 Event-Driven Programming and Basic GUI Objects.
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
Introduction Many Java application use a graphical user interface or GUI (pronounced “gooey”). A GUI is a graphical window or windows that provide interaction.
Events and Event Handling
Graphical User Interfaces
CompSci 230 S Programming Techniques
Chapter 36 JavaBeans and Bean Events
Web Design & Development Lecture 11
A First Look at GUI Applications
“Form Ever Follows Function” Louis Henri Sullivan
GUIs Model/View/Controller Layouts
Architectural Patterns for Interactive Software
A Quick Java Swing Tutorial
Ellen Walker Hiram College
MVC Paradigm The MVC paradigm breaks applications or interfaces into three parts: the model, the view, and the controller. A --> 25 % B --> 60 % C -->
GUI Event Handling Nithya Raman.
Event-driven programming for GUI
Course Outcomes of Advanced Java Programming AJP (17625, C603)
Design Patterns in Swing and AWT
Timer class and inner classes
Introduction to Event Handling
Steps to Creating a GUI Interface
A Quick Java Swing Tutorial
Advanced Programming in Java
11.1 Applets & graphics.
Graphical User Interface
Presentation transcript:

Review: Java GUI Programming R.E. Johnson, Frameworks=(Components + Patterns), CACM, 4(10):39-42, October 1997. J. Elliott, et al., Java Swing, 2nd edition, O’Reilly, 2002.

Outline Frameworks MVC model Elements of GUI frameworks GUI components (views and widgets) Layout managers Handling events Lab: Timer applet

Object-Oriented Framework A set of cooperating (abstract) classes and interface that: Represent reusable designs of software systems in a particular application domain, Provide semi-complete applications that can be specialized to produce custom applications, and Defines conventions for extending the abstract classes, implementing the interfaces, and allowing their instances to interact with one another

Examples GUI Small Network/Distributed/Web Applets, … AWT, Swing, SWT (Eclipse) MFC, … Network/Distributed/Web RMI, J2EE, CORBA, Drupal (PHP), …

Why Frameworks? Benefits To support reuse of design and implementations in particular application domains Benefits Quick and easy application development Reliable application (i.e., high confidence) Standardized applications

Characteristics of Frameworks Extensibility Inversion of control Design patterns as building blocks Code written by programmer Library code Application (master) Component (slave) Library-based Framework code Code written by programmer Framework-based

Outline Frameworks MVC model Elements of GUI frameworks GUI components (views and widgets) Layout managers Handling events Lab: Timer applet

GUI Framework in General MVC metaphor for separation of concerns Event-based, implicit invocation style Single vs. multithreading

MVC Metaphor A way of cleanly breaking an application into three parts Model for maintaining data, View for displaying all or a portion of the data, and Controller for handling events that affect the model or views. View Controller Model

Separating M from VC View Controller Model changes get data from model changes model or view View Controller Model update view when data changes

Due to Separation … Multiple views and controllers for models. New views and controllers can be added for the model. Changes in views are localized; such changes have minimal or no impact on the model.

Outline Frameworks MVC model Elements of GUI frameworks GUI components (views and widgets) Layout managers Handling events Lab: Timer applet

GUI Framework Classes GUI components (views and widgets) JButton, JLabel, JTextField, JPanel, … Layout managers FlowLayout, BorderLayout, GridBagLayout, … Events and event listeners ActionEvent, ActionListener, … Graphics, imaging, and other multimedia classes

Event Handling Mechanism to write control code Composed of: Event Event source Event listener (or handler)

Event Handling (Cont.) Event Event source A way for GUI components to communicate with the rest of application Implemented as event classes (e.g., ActionEvent) Event source Components generating events Examples: buttons, check boxes, combo boxes, etc.

Event Handling (Cont.) Event listener (or handler) Objects that receives and processes events Must implement an appropriate listener interface Must inform the source its interest in handling a certain type of events (by registering) May listen to several sources and different types of events

Example // create a button JButton button = new JButton(“Start”); // register an action listener button.addActionListener(new StartButtonActionListener()); // Action listener class class StartButtonActionListener implements ActionListener { public void actionPerformed(ActionEvent e) { // handle the event e … System.out.println(“Start button pressed!”); }

Using Anonymous Class // create a button JButton button = new JButton(“Start”); // register an action listener button.addActionListener(new ActionListener { public void actionPerformed(ActionEvent e) { // handle the event e … System.out.println(“Start button pressed!”); } });

Using Lambda Notation (Java 8) // create a button JButton button = new JButton(“Start”); // register an action listener button.addActionListener(e -> { // handle the event e … System.out.println(“Start button pressed!”); });

Example (Cont.) b: JButton h: ActionListener addActionListener(h) <<create>> e: ActionEvent actionPerformed(e) Observer design pattern getSource()

Lab (Pair): Timer Applet Write a timer applet incrementally (see handout) Use MVC by defining a model class, say TimerModel. init destroy start stop Applet lifecycle public class TimerApplet extends JApplet { private final TimerModel timerModel = new TimerModel(); public void init() { /* configure UI. */ } }