Lecture 261 CS110 Lecture 26 Thursday, May 6, 2004 This lecture not delivered from slides Announcements –final exam Thursday, May 20, 8:00 AM McCormack,

Slides:



Advertisements
Similar presentations
1 Graphical User Interface (GUI) Applications Abstract Windowing Toolkit (AWT) Events Handling Applets.
Advertisements

Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Drawing in a frame – Java GUI
Graphic User Interfaces Layout Managers Event Handling.
TCU CoSc Programming with Java Handling Events.
June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 1 Lecture 9 Object Oriented Programming in Java Advanced Topics Abstract Windowing.
Lecture 24 Applets. Introduction to Applets Applets should NOT have main method but rather init, stop, paint etc They should be run through javac compiler.
CS3157 Java UI Recitation. Material Covered: Overview of AWT components, Event Handling, creating applets, and sample UI. Not covered in recitation: Drawing,
GUI and Event-Driven Programming Recitation – 3/6/2009 CS 180 Department of Computer Science, Purdue University.
1 lecture 12Lecture 13 Event Handling (cont.) Overview  Handling Window Events.  Event Adapters Revisited.  Introduction to Components and Containers.
Lecture 241 CS110 Lecture 25 Tuesday, May 4, 2004 Announcements –final exam Thursday, May 20, 8:00 AM McCormack, Floor 01, Room 0608 (easier than last.
Java GUI building with the AWT. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many.
10.1 AWT The AWT classes Users today expect a Graphical User Interface (GUI) Improves application usability Difficult to implement cross-platform.
Chapter 9: Applets Jim Burns Fall Outline Learn about applets Learn about applets Write an HTML doc to host an applet Write an HTML doc to host.
ACM/JETT Workshop - August 4-5, ExceptionHandling and User Interfaces (Event Delegation, Inner classes) using Swing.
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 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Lesson 27: Introduction to the Java GUI. // helloworldbutton.java import java.awt.*; import javax.swing.*; class HelloButton{ public static void main.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Graphical User Interface CSI 1101 N. El Kadri. Plan - agenda Graphical components Model-View-Controller Observer/Observable.
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.
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,
Java GUI building with Swing. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
C H A P T E R T E N Event-Driven Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
Objectives of This Session
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
Graphics in Java Starring: NetBeans Co-Starring: Java.awt.
1 Block1 – unit 2 (The Case study in Budd 5-6).  create a small application that uses the Abstract Windowing Toolkit (AWT)  Swing packages to simulate.
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
– Advanced Programming P ROGRAMMING IN Lecture 21 Introduction to Swing.
CSC 205 – Java Programming II Applet. Types of Java Programs Applets Applications Console applications Graphics applications Applications are stand-alone.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
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.
Swing GUI Components You can create graphics components to place on your applet using classes available in the Swing package ( javax.swing ) Class names.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
 GUI – Graphic User Interface  Up to now in the programs we have written all output has been sent to the standard output device i.e.: the DOS console.
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
Lec.10 (Chapter 8 & 9) GUI Jiang (Jen) ZHENG June 27 th, 2005.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
1 Applications & Applets Standalone applications & Java applets Peter Mozelius DSV/UCSC.
Java Swing One of the most important features of Java is its ability to draw graphics.
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.
Lesson 28: More on the GUI button, frame and actions.
Event Handling CS 21a: Introduction to Computing I First Semester,
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.
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.
Java Swing and Events Chris North cs3724: HCI. Presentations nadine edwards, steve terhar Vote: UI Hall of Fame/Shame?
Event Driven (Asynchronous) Programming. Event handling in Unity Subclass a class that contains event handling methods, and then override those methods.
AWT Vs SWING. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many applications Uses.
CSC 205 Programming II Lecture 5 AWT - I.
GUI building with the AWT
Welcome To java
Java Events. Java Events Important definitions Overridden method Class vs. abstract class vs. interface Event Handling Definition Main components Windows.
A First Look at GUI Applications
Lecture 09 Applets.
Ellen Walker Hiram College
Event Handling CS 21a: Introduction to Computing I
Java Applets.
GUI building with the AWT
Graphical User Interfaces in Java Event-driven programming
Constructors, GUI’s(Using Swing) and ActionListner
GUI building with the AWT
Session 29 Introducing CannonWorld (Event-driven Programming)
Presentation transcript:

Lecture 261 CS110 Lecture 26 Thursday, May 6, 2004 This lecture not delivered from slides Announcements –final exam Thursday, May 20, 8:00 AM McCormack, Floor 01, Room 0608 –wise1 due next Tuesday Agenda –Questions (WISE and otherwise) –GUI programming –Interfaces

Lecture 262 GUI Programming Fun –some introductory courses start here –requires hardware support (PCs) –maybe more in CS110 in time GUI syntax: what windows look like - containers and components GUI semantics: how windows behave – event driven programming System does lots of work for you Learn the APIs, use software tools

Lecture /joi

Lecture 264 GUI Syntax (what windows look like) AWT (Abstract Windowing Toolkit) Abstract class Container –subclasses: Panel, Window, Frame –methods: add, setLayout Abstract class Component –subclasses: Button, Checkbox, Textfield, Up to date Java GUI programmers use swing: –classes: JButton, JTextfield,… or they use GUI builders

Lecture 265 Building window look and feel class JOIPanel extends Applet extends Panel init method creates a button and adds it to this Panel, sets font: 38 button = new Button( "Press Me" ); 39 this.add( button ); 40 font = new Font("Garamond", Font.BOLD, 48);

Lecture 266 Building window behavior Add a listener to the button 43 button.addActionListener( new JOIButtonListener( this ) ); When button is pressed, system sends an actionPerformed message to the listener To see what happens, look at method actionPerformed in class JOIButtonListener

Lecture 267 JOIButtonListener // constructor remembers the Panel 27 public JOIButtonListener ( JOIPanel panel ) 28 { 29 this.panel = panel; 30 } // send panel a changeMessage message now! 41 public void actionPerformed ( ActionEvent e ) 42 { 43 panel.changeMessage(); 44 }

Lecture 268 Changing the message In JOIPanel: change the message and ask the system to repaint: 51 public void changeMessage() 52 { 53 currentMessage = 54 currentMessage.equals(MESSAGE1) ? MESSAGE2 : MESSAGE1; 55 this.repaint(); 56 }

Lecture 269 Changing the message repaint( ) (which is really super.repaint( )) invokes paint( ) A Graphics object is like a programmable pen or paintbrush 67 public void paint(Graphics g) 68 { 69 g.setColor(Color.black); 70 g.setFont(font); 71 g.drawString(currentMessage, 40, 75); 72 }

Lecture 2610 Running the program as an application > java JOIPanel public static void main( String[] args ) { Terminal t = new Terminal(); Frame frame = new Frame(); JOIPanel panel = new JOIPanel(); panel.init(); frame.add(panel); frame.setSize(400,120); frame.show(); t.readLine("return to close window "); System.exit(0); }

Lecture 2611 Running the program as an applet from a browser: file joi.html This file is written in html (“hypertext markup language”), not Java. Browsers understand html. main method never runs. Execution starts with init.

Lecture 2612 Interfaces An interface is like a very abstract class –no fields –only abstract methods A class that implements an interface promises to implement its abstract methods public class JOIButtonListener implements ActionListener

Lecture 2613

Lecture 2614 All together now public class JOIApplet extends Applet implements ActionListener {... public void actionPerformed ( ActionEvent e ) { currentMessage = currentMessage.equals(MESSAGE1) ? MESSAGE2 : MESSAGE1; this.repaint(); }

Lecture 2615 Interfaces in Collection framework Inheritance hierarchy (classes) java.lang.Object java.util.AbstractMap java.util.TreeMap TreeMap implements interfaces: –Cloneable, Map, Serializable, SortedMap AbstractMap implements Map Map foo = new TreeMap( ) // legal

Lecture 2616 Juno 10 has a GUI Juno CLI prompts for input when it wants it => the program is in control Juno GUI sits waiting for user input from anywhere mouse can go, then takes action => the user is in control (event driven) > java Juno –g.

Lecture 2617 java Juno -e -g