EPITA Première Année Cycle Ingénieur. Atelier Java - J5

Similar documents
Graphical User Interfaces (GUIs)

Heavyweight with platform-specific widgets. AWT applications were limited to commonfunctionality that existed on all platforms.

(Incomplete) History of GUIs

Graphic User Interfaces. - GUI concepts - Swing - AWT

State Application Using MVC

Swing: Building GUIs in Java

Swing: Building GUIs in Java

All the Swing components start with J. The hierarchy diagram is shown below. JComponent is the base class.

[module lab 2.2] GUI FRAMEWORKS & CONCURRENCY

Jonathan Aldrich Charlie Garrod

Java for Interfaces and Networks (DT3010, HT10)

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in

KF5008 Program Design & Development. Lecture 1 Usability GUI Design and Implementation

encompass a group of features for building Graphical User Interfaces (GUI).

Java for Interfaces and Networks (DT3029)

Introduction to Graphical Interface Programming in Java. Introduction to AWT and Swing

Introduction to the JAVA UI classes Advanced HCI IAT351

Introduction to GUIs. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2014

Graphical interfaces & event-driven programming

Java: Graphical User Interfaces (GUI)

Graphical User Interface (GUI)

Java Swing Introduction

CSC207 Week 4. Larry Zhang

Command-Line Applications. GUI Libraries GUI-related classes are defined primarily in the java.awt and the javax.swing packages.

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

Graphical User Interface (GUI)

Chapter 8. Java continued. CS Hugh Anderson s notes. Page number: 264 ALERT. MCQ test next week. This time. This place.

Widgets. Overview. Widget. Widgets Widget toolkits Lightweight vs. heavyweight widgets Swing Widget Demo

Java continued. Chapter 8 ALERT ALERT. Last week. MCQ test next week. This time. This place. Closed book. Assignment #2 is for groups of 3

Interfaces & Polymorphism part 2: Collections, Comparators, and More fun with Java graphics

Chapter 9 Designing Graphical User Interfaces (GUIs)

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User

Object-Oriented Programming Design. Topic : Graphics Programming GUI Part I

User interfaces and Swing

Programming Languages and Techniques (CIS120)

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread

CS 251 Intermediate Programming GUIs: Event Listeners

GUI and its COmponent Textfield, Button & Label. By Iqtidar Ali

Using Several Components

Graphics programming. COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson)

Java. GUI building with the AWT

Part I: Learn Common Graphics Components

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!

CS 251 Intermediate Programming GUIs: Components and Layout

Midterm assessment - MAKEUP Fall 2010

Java Swing. based on slides by: Walter Milner. Java Swing Walter Milner 2005: Slide 1

Dr. Hikmat A. M. AbdelJaber

Introduction to concurrency and GUIs

GUI Basics. Object Orientated Programming in Java. Benjamin Kenwright

Widget Toolkits CS MVC

CS108, Stanford Handout #22. Thread 3 GUI

G51PGP Programming Paradigms. Lecture 009 Concurrency, exceptions

CHAPTER 1: A GENERAL INTRODUCTION TO PROGRAMMING 1

CS11 Java. Fall Lecture 4

MTAT Systems Modelling Statechart modeling, simulation and execution using Yakindu

Window Interfaces Using Swing Objects

Building Graphical User Interfaces. Overview

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

Chris9an Kästner Charlie Garrod

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

Systems Programming. Bachelor in Telecommunication Technology Engineering Bachelor in Communication System Engineering Carlos III University of Madrid

17 GUI API: Container 18 Hello world with a GUI 19 GUI API: JLabel 20 GUI API: Container: add() 21 Hello world with a GUI 22 GUI API: JFrame: setdefau

CS 4300 Computer Graphics

Overview. Building Graphical User Interfaces. GUI Principles. AWT and Swing. Constructing GUIs Interface components GUI layout Event handling

Building Graphical User Interfaces. GUI Principles

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing

Java Swing. Recitation 11/(20,21)/2008. CS 180 Department of Computer Science, Purdue University

SE1021 Exam 2. When returning your exam, place your note-sheet on top. Page 1: This cover. Page 2 (Multiple choice): 10pts

CS415 Human Computer Interaction

Lecture 9. Lecture

Programmierpraktikum

Graphical User Interface (Part-1) Supplementary Material for CPSC 233

1. Swing Note: Most of the stuff stolen from or from the jdk documentation. Most programs are modified or written by me. This section explains the

Graphical User Interfaces

Virtualians.ning.pk. 2 - Java program code is compiled into form called 1. Machine code 2. native Code 3. Byte Code (From Lectuer # 2) 4.

CS 2112 Lecture 20 Synchronization 5 April 2012 Lecturer: Andrew Myers

TYPES OF INTERACTORS Prasun Dewan Department of Computer Science University of North Carolina at Chapel Hill

Lecture 3: Java Graphics & Events

VizzAnalyzer goes Eclipse!

Part 3: Graphical User Interface (GUI) & Java Applets

Sketchpad. Plan for Today. Class 22: Graphical User Interfaces IBM 705 (1954) Computer as Clerk : Augmenting Human Intellect

Chapter 13 Lab Advanced GUI Applications

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

Simplifying Development and Testing of GUIs with SAF (JSR 296) and FEST. Michael Hüttermann Training & Consulting Alex Ruiz Oracle Corporation

Graphical User Interfaces in Java Part 2

Building Java Programs Bonus Slides

Graphical User Interfaces 2

Beyond CSE143. What s Left To Do? Templates. Using Templates. A Template Class. A Problem with Reusing Code CSE 143

Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling

CSE 331 Software Design & Implementation

Object-Oriented Programming: Revision. Revision / Graphics / Subversion. Ewan Klein. Inf1 :: 2008/09

Window Interfaces Using Swing Objects

Graphical User Interfaces. Comp 152

GUI Output. Adapted from slides by Michelle Strout with some slides from Rick Mercer. CSc 210

Abstract, Interface, GUIs. Ch. 11 & 16

Charlie Garrod Michael Hilton

Packages: Putting Classes Together

Advanced Java Programming. Swing. Introduction to Swing. Swing libraries. Eran Werner, Tel-Aviv University Summer, 2005

Transcription:

EPITA Première Année Cycle Ingénieur marwan.burelle@lse.epita.fr http://www.lse.epita.fr

Overview 1 2

Different toolkits AWT: the good-old one, lakes some features and has a plateform specific look n feel (anyway, AWT is deprecated) Swing: a better AWT with a unified Look n feel and better drawing algorithms. SWT: the toolkit from Eclipse backed on native toolkits.

Swing Swing could have been a demonstration of classical design patterns in action, the whole concept heavily relies on: Decorator Composite Facade Chain of responsibility (internal) A graphical application in Java can be seen as tree (Composite) rooted by a JFrame and where nodes are widget and layout. The layout concept help you hierarchically describes your interface and provide a nive way to organize your widget The whole API is event-driven meaning that all you have to do is to connect event and operations triggered by those events.

SwingSet2 demo

Exploring The BorderLayout SimpleFrame import javax.swing.*; import java.awt.borderlayout; import java.awt.container; import java.awt.dimension; public class SimpleFrame { public static void main(string[] args) { javax.swing.swingutilities.invokelater( new Runnable() { public void run() { show(); );

Exploring The BorderLayout SimpleFrame private static void show() { JFrame frame = new JFrame("BorderLayout"); frame.setdefaultcloseoperation( JFrame.EXIT_ON_CLOSE); JButton labelt = new JButton("Top"); JButton labelb = new JButton("Bottom"); JButton labelc = new JButton("Center"); JButton labell = new JButton("Left"); JButton labelr = new JButton("Right"); Container pane = frame.getcontentpane(); pane.add(labelt, BorderLayout.PAGE_START); pane.add(labelb, BorderLayout.PAGE_END); pane.add(labelc, BorderLayout.CENTER); pane.add(labell, BorderLayout.LINE_START); pane.add(labelr, BorderLayout.LINE_END); frame.pack(); frame.setvisible(true);

Adding an Event Listener SimpleFrame static void addbuttonevent(final JButton b) { final String name = b.gettext(); ActionListener listener = new ActionListener() { int c = 0; public void actionperformed(actionevent e) { out.println(name); c++; b.settext(name + " clicked (" + c + ")"); ; b.addactionlistener(listener);

We Got Threads? A swing application always runs with 3 threads doing separate works in order to keep the application the most responsible as possible: Initial Thread: the threads that execute initial application code. Event Dispatch Thread: where all the stuff about event is done. Worker Threads: where the background heavy work is done. These threads are created directly by the framework, the only things you need to know is how to interract with them.

Initial Threads The only role of the initial thread is to launch the invoke the GUI creation that will be run by the Event Dispatch Thread. Syntax: invokelater javax.swing.swingutilities.invokelater( new Runnable() { public void run() { BuildGUI(); );

Event Dispatch Thread The place for all event and swing activities Almost all swing action must be done in that thread: swing operations are not thread safe, so we must keep them bound to one thread. Task in the Event Dispatch Thread must be short: if a task take too long, it will make the interface unresponsive or freezing Globaly, if you start your GUI with the previous method, it will run on the wrigth thread.

Worker Threads Background taskes (often long one) are supposed to run asynchronously with the GUI and thus run on one or more Worker Threads. javax.swing.swingworker is an abstract class used to build task to be scheduled on the worker threads. You must define a method doinbackground that launch the work You may define also a method called done that will be executed by the Event Dispatch Thread. javax.swing.swingworker implements the Futur<T> interface and thus we are able to wait for result using method get. Beware, get is blocking and you ll probably invoke it from the Event Dispatch Thread, it then can freeze your interface. There s an overloaded variant of get taking a time-out value to avoid long waiting.

Live Updates We sometime need to push update to the interface before the end of the computation. javax.swing.swingworker provides a method publish that let you make values available for the Event Dispatch Thread. The Event Dispatch Thread will access these values through the method process that you thus need to override.

Workers Syntax: SwingWorker class MyWorker extends SwingWorker<O, I> { O doinbackground() { // do your job here // and public sometimes... publish(new I(...)); void process(list<i> values) { // display things here

Other Tools You can cancel a running job from the Event Dispatch Thread using the method worker.cancel(true) The worker will be able to test the cancelation state using the method iscancelled() You can use the progress property (an int ranging from 0 to 100) to indicate progression (using setprogress and getprogress) You also have the state variable indicating the current state through the possible values: PENDING, STARTED, DONE