Principles of Software Construction: Objects, Design and Concurrency. GUIs with Swing. toad 15-214. Spring 2013



Similar documents
GUIs with Swing. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2012

GUI Event-Driven Programming

Model-View-Controller (MVC) Design Pattern

Programming with Java GUI components


Developing GUI Applications: Architectural Patterns Revisited

Swing. A Quick Tutorial on Programming Swing Applications

CS 335 Lecture 06 Java Programming GUI and Swing

Assignment # 2: Design Patterns and GUIs

Nexawebホワイトペーパー. Developing with Nexaweb ~ Nexaweb to Improve Development Productivity and Maintainability

Event processing in Java: what happens when you click?

Karsten Lentzsch JGoodies SWING WITH STYLE

Extending Desktop Applications to the Web

The Abstract Windowing Toolkit. Java Foundation Classes. Swing. In April 1997, JavaSoft announced the Java Foundation Classes (JFC).

@ - Internal # - Online TH PR OR TW TOTAL HOURS # @ 175

Implementação. Interfaces Pessoa Máquina 2010/ Salvador Abreu baseado em material Alan Dix. Thursday, June 2, 2011

Syllabus for CS 134 Java Programming

The Basic Java Applet and JApplet

How To Use The Command Pattern In Java.Com (Programming) To Create A Program That Is Atomic And Is Not A Command Pattern (Programmer)

JMulTi/JStatCom - A Data Analysis Toolkit for End-users and Developers

Principles of Software Construction: Objects, Design, and Concurrency. Course Introduction. toad. toad Fall School of Computer Science

Fondamenti di Java. Introduzione alla costruzione di GUI (graphic user interface)

JIDE Action Framework Developer Guide

core 2 Handling Mouse and Keyboard Events

5.17 GUI. Xiaoyi Jiang Informatik I Grundlagen der Programmierung

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 7: Object-Oriented Programming. Introduction

Tutorial Reference Manual. Java WireFusion 4.1

Mouse Event Handling (cont.)

JiST Graphical User Interface Event Viewer. Mark Fong

ARCHITECTURAL DESIGN OF MODERN WEB APPLICATIONS

Generation and Handcoding

Java is commonly used for deploying applications across a network. Compiled Java code

COMMUNITY COLLEGE OF CITY UNIVERSITY CITY UNIVERSITY OF HONG KONG

How To Build A Swing Program In Java.Java.Netbeans.Netcode.Com (For Windows) (For Linux) (Java) (Javax) (Windows) (Powerpoint) (Netbeans) (Sun) (

Automated Data Collection for Usability Evaluation in Early Stages of Application Development

Stock Trader System. Architecture Description

How Scala Improved Our Java

Computing Concepts with Java Essentials

Cours de Java. Sciences-U Lyon. Java - Introduction Java - Fondamentaux Java Avancé.

Java EE Web Development Course Program

During the process of creating ColorSwitch, you will learn how to do these tasks:

GUI Components: Part 2

Advanced Network Programming Lab using Java. Angelos Stavrou

Android Application Development Course Program

CaptainCasa. CaptainCasa Enterprise Client. CaptainCasa Enterprise Client. Feature Overview

High-level Design. What is software architecture?

Management Information Systems 260 Web Programming Fall 2006 (CRN: 42459)

Patterns in. Lecture 2 GoF Design Patterns Creational. Sharif University of Technology. Department of Computer Engineering

Collaborative GeoGebra

MiniDraw Introducing a framework... and a few patterns

Draw pie charts in Excel

- User input includes typing on the keyboard, clicking of a mouse, tapping or swiping a touch screen device, etc.

Graphical User Interfaces

Word basics. Before you begin. What you'll learn. Requirements. Estimated time to complete:

Case studies: Outline. Requirement Engineering. Case Study: Automated Banking System. UML and Case Studies ITNP090 - Object Oriented Software Design

Structural Patterns. Structural Patterns. Fritz Solms. October 16, 2015

Example. Represent this as XML

CS Mobile Development for Social Change

Eclipse with Mac OSX Getting Started Selecting Your Workspace. Creating a Project.

UI software architectures & Modeling interaction

INTERNET PROGRAMMING AND DEVELOPMENT AEC LEA.BN Course Descriptions & Outcome Competency

A LITTLE PROMISE FROM YOU

Android Developer Fundamental 1

BPMS BUYER S TOOL KIT. Sample Request for Proposal for a Business Process Management Suite. Part 1 of the complete BPMS Buyer s Tool Kit

Auto Clicker Tutorial

Software Design: Figures

3. Locate the different selections of Styles from the Home Tab, Styles Group

CS330 Design Patterns - Midterm 1 - Fall 2015

Essentials of the Java(TM) Programming Language, Part 1

M-Files Gantt View. User Guide. App Version: Author: Joel Heinrich

Demo: Embedding Windows Presentation Foundation elements inside a Java GUI application. Version 7.3

Using A Frame for Output

An introduction to creating JSF applications in Rational Application Developer Version 8.0

Definition of SOA. Capgemini University Technology Services School Capgemini - All rights reserved November 2006 SOA for Software Architects/ 2

GUI and Web Programming

Application Programming on the Mac COSC346

Summer Internship 2013

Homework/Program #5 Solutions

TIPS FOR USING OS X 10.8 MOUNTAIN LION

11. Applets, normal window applications, packaging and sharing your work

Lecture 1 Introduction to Android

Architectural Patterns. Layers: Pattern. Architectural Pattern Examples. Layer 3. Component 3.1. Layer 2. Component 2.1 Component 2.2.

Contents. Introduction and System Engineering 1. Introduction 2. Software Process and Methodology 16. System Engineering 53

To begin, visit this URL:

Introducing Apache Pivot. Greg Brown, Todd Volkert 6/10/2010

ORACLE MOBILE APPLICATION FRAMEWORK DATA SHEET

ios Design Patterns Jackie Myrose CSCI 5448 Fall 2012

A Short Introduction to Android

Universität Karlsruhe (TH) Forschungsuniversität gegründet Inheritance Depth as a Cost Factor in Maintenance

Designing and Writing a Program DESIGNING, CODING, AND DOCUMENTING. The Design-Code-Debug Cycle. Divide and Conquer! Documentation is Code

As you look at an imac you will notice that there are no buttons on the front of the machine as shown in figure 1.

Module 9. User Interface Design. Version 2 CSE IIT, Kharagpur

Introduction to Android: Hello, Android! 26 Mar 2010 CMPT166 Dr. Sean Ho Trinity Western University

Tutorial: Time Of Day Part 2 GUI Design in NetBeans

This course provides students with the knowledge and skills to develop ASP.NET MVC 4 web applications.

Frequently Asked Questions

Asset Track Getting Started Guide. An Introduction to Asset Track

Generating Automated Test Scripts for AltioLive using QF Test

Lab 9. Spam, Spam, Spam. Handout 11 CSCI 134: Spring, To gain experience with Strings. Objective

Windows Basics. Developed by: D. Cook

Transcription:

Principles of Software Construction: Objects, Design and Concurrency GUIs with Swing 15-214 toad Spring 2013 Christian Kästner Charlie Garrod School of Computer Science 2012-13 C Garrod, C Kästner, J Aldrich, and W Scherlis

Administrivia Midterm results Homework 4a grading expected by tonight Feedback on your design and design questions for 4b Homework 4b due Tuesday after spring break toad 2

Recap from last week toad 3

Event-based programming A style of programming where the control-flow of the program is driven by (usually-) external events public void performaction(actionevent e) { List<String> lst = Arrays.asList(bar); foo.peek(42) } public void performaction(actionevent e) { bigbloatedpowerpointfunction(e); withanamesolongimadeittwomethods(e); yesiknowjavadoesntworklikethat(e); } public void performaction(actionevent e) { List<String> lst = Arrays.asList(bar); foo.peek(40) } toad 4

Reacting to events - from framework Setup phase Describe how the GUI window should look Use libraries for windows, widgets, and layout Embed specialized code for later use Customization (provided during setup) New widgets that display themselves in custom ways How to react to events Execution Framework gets events from OS Mouse clicks, key presses, window becomes visible, etc. Framework triggers application code in response The customization described above Application event mouse, key, redraw, GUI Framework get event OS drawing commands next event toad 5 5

GUI Frameworks in Java AWT Native widgets, only basic components, dated Swing Java rendering, rich components SWT + JFace Mixture of native widgets and Java rendering; created for Eclipse for faster performance Others Apache Pivot, SwingX, JavaFX, toad 6

Swing JFrame JPanel JButton JTextField toad 7

Swing Layout Manager see http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html toad 8

Find the pattern contentpane.setlayout(new BorderLayout(0,0)); contentpane.setborder(new EmptyBorder(5, 5, 5, 5)); toad 9

Behavioral: Strategy Applicability Many classes differ in only their behavior Client needs different variants of an algorithm Consequences Code is more extensible with new strategies Compare to conditionals Separates algorithm from context each can vary independently Adds objects and dynamism code harder to understand Common strategy interface may not be needed for all Strategy implementations may be extra overhead toad 10

Design Pattern in Swing Observer Pattern Strategy Pattern Composite Pattern Command Patterns (Actions) Model View Controller Pattern Controller / Facade toad 11

Swing has lots of event listener interfaces: ActionListener AdjustmentListener FocusListener ItemListener KeyListener MouseListener TreeExpansionListener TextListener WindowListener and on and on toad 12 12

Reminder: The Observer design pattern Applicability When an abstraction has two aspects, one dependent on the other, and you want to reuse each When change to one object requires changing others, and you don t know how many objects need to be changed When an object should be able to notify others without knowing who they are Consequences Loose coupling between subject and observer, enhancing reuse Support for broadcast communication Notification can lead to further updates, causing a cascade effect toad 13

JButton btnnewbutton = new JButton("New button"); btnnewbutton.addactionlistener(new ActionListener() { public void actionperformed(actionevent e) { counter.inc(); } }); btnnewbutton.addactionlistener(new ActionListener() { public void actionperformed(actionevent e) { JOptionPane.showMessageDialog(null, "button clicked", "alert", JOptionPane.ERROR_MESSAGE); } }); panel.add(btnnewbutton, BorderLayout.SOUTH); toad 14

class MyButton extends JButton { Counter counter; public MyButton() { settitle } protected void fireactionperformed(actionevent event) { counter.inc(); } } JButton btnnewbutton = new MyButton(); panel.add(btnnewbutton, BorderLayout.SOUTH); toad 15

GUI design issues Interfaces vs. inheritance Inherit from JPanel with custom drawing functionality Implement the ActionListener interface, register with button Why this difference? Models and views toad 16 16

GUI design issues Interfaces vs. inheritance Inherit from JPanel with custom drawing functionality Subclass is a special kind of Panel The subclass interacts closely with the JPanel e.g. the subclass calls back with super() The way you draw the subclass doesn t change as the program executes Implement the ActionListener interface, register with button The action to perform isn t really a special kind of button; it s just a way of reacting to the button. So it makes sense to be a separate object. The ActionListener is decoupled from the button. Once the listener is invoked, it doesn t call anything on the Button anymore. We may want to change the action performed on a button press so once again it makes sense for it to be a separate object Models and views toad 17 17

Command Pattern implementable AbstractAction can serve as command pattern Action openaction = new AbstractAction("open ") { public void actionperformed(actionevent e) { } } filemenu.add(openaction); see also javax.swing.undo package toad 18

Reminder: Command Applicability Parameterize objects by an action to perform Specify, queue and execute requests at different times Support undo Support logging changes that can be reapplied after a crash Structure a system around high-level operations built out of primitives Consequences Decouples the object that invokes the operation from the one that performs it Since commands are objects they can be explicitly manipulated Can group commands into composite commands Easy to add new commands without changing existing code toad 19

JComponent toad 20

Reminder: Factory Method Applicability A class can t anticipate the class of objects it must create A class wants its subclasses to specify the objects it creates Consequences Provides hooks for subclasses to customize creation behavior Connects parallel class hierarchies toad 21

Nesting Containers toad 22

Reminder: Composite Applicability You want to represent partwhole hierarchies of objects You want to be able to ignore the difference between compositions of objects and individual objects Consequences Makes the client simple, since it can treat objects and composites uniformly Makes it easy to add new kinds of components Can make the design overly general Operations may not make sense on every class Composites may contain only certain components toad 23

Model-View-Controller (MVC) Manage inputs from user: mouse, keyboard, menu, etc. Manage display of information on the screen Manage data related to the application domain toad 24

Model-View-Controller (MVC) Passive model Active model http://msdn.microsoft.com/en-us/library/ff649643.aspx toad 25

Separating Application Core and GUI Reduce coupling Create core of the application working and testable without a GUI Use Observer pattern to communicate information from Core (Model) to GUI (View) Use Controller (Façade) to perform operations on core May run in separate threads (worker thread vs GUI thread) to avoid blocking, see SwingWorker GUI Tests GUI GUI Core Tests Core toad 26

toad 27

Summary GUIs are full of design pattern Swing for Java GUIs Separation of GUI and Core toad 28