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.

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.
Java Graphical User Interface (GUI) using Visual Editor in eclipse CSI 1390 – Java Programming Instructor: Saeid Nourian University.
Drawing in a frame – Java GUI
Graphic User Interfaces Layout Managers Event Handling.
TCU CoSc Programming with Java Handling Events.
Introduction to Java Classes, events, GUI’s. Understand: How to use TextPad How to define a class or object How to create a GUI interface How event-driven.
Event Handling. In this class we will cover: Basics of event handling The AWT event hierarchy Semantic and low-level events in the AWT.
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.
1 lecture 12Lecture 13 Event Handling (cont.) Overview  Handling Window Events.  Event Adapters Revisited.  Introduction to Components and Containers.
Java GUI building with the AWT. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many.
Lesson 35: Review of the Java GUI. The JFrame, Container and JButton.
Io package as Java’s basic I/O system continue’d.
Applets Java API.
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.
Intro to GUIs (Graphical User Interfaces) Section 2.5Intro. to GUIs: a GUI Greeter Section 3.7Graphical/Internet Java: Einstein's Equation.
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.
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.
Lecture 21 CS110 Lecture 2 January 29, 2004 Announcements –hw1 part 1 – due right now –hw1 part 2 – due Tuesday night Questions Agenda –turnin –Object.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
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.
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.
Lecture 101 CS110 Lecture 10 Thursday, February Announcements –hw4 due tonight –Exam next Tuesday (sample posted) Agenda –questions –what’s on.
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.
Applets Yong Choi School of Business CSU, Bakersfield.
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
For (int i = 1; i
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.
May 12, 1998CS102-01Lecture 7-3 Building GUIs in Java I CS Lecture 7-3 A picture's worth a thousand words.
Architectural Patterns Support Lecture Patterns Pattern: A representation of a proven solution. Problem Applicable Forces Solution Consequences Benefits.
Java Swing One of the most important features of Java is its ability to draw graphics.
Creating a GUI Class An example of class design using inheritance and interfaces.
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,
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.
Java Threads 1 1 Threading and Concurrent Programming in Java Threads and Swing D.W. Denbo.
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.
Lecture 241 CS110 Lecture 24 Thursday, April 29, 2004 Announcements –exam answers, final project (WISE) posted –final exam Thursday, May 20, 8:00 AM McCormack,
Multiple buttons and action calls
GUIs and Events Rick Mercer.
GUI building with the AWT
Lecture 09 Applets.
“Form Ever Follows Function” Louis Henri Sullivan
Ellen Walker Hiram College
Event Handling CS 21a: Introduction to Computing I
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
Presentation transcript:

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 Tuesday’s!) –wise0 due tonight Agenda –Questions (WISE and otherwise) –Persistence –GUI programming –Interfaces

Lecture 242 Persistence Bank and Juno should remember state between invocations read state from a file at startup write state back to file at exit Can imagine a text representation of the state Better: Java knows how to save whole Objects

Lecture 243 Bank (version 9) Bank instance can be saved to a file java Bank –f bankFileName live demo … if –f bankFileName && file exists read Bank from that file else create new Bank() visit bank if –f bankFileName write Bank to that file

Lecture 244 Bank (version 9) public class Bank implements Serializable java Bank –f bankFileName if (bankFileName == null) { theBank = new Bank( bankName ); } else { theBank = readBank ( bankName, bankFileName ); }

Lecture 245 Read Bank instance from a file private static Bank readBank( String bankName, String bankFileName) { File file = new File( bankFileName ); if (!file.exists()) { return new Bank( bankName ); } ObjectInputStream inStream = null; try { inStream = new ObjectInputStream( new FileInputStream( file ) ); Bank bank = (Bank)inStream.readObject(); System.out.println( "Bank state read from file " + bankFileName); return bank; }

Lecture 246 Why read/write only Bank? BankAccount and Month are also Serializable Bank box-and-arrow picture shows that all objects of all types are pointed to (indirectly) by arrows starting in the Bank private transient Terminal atm; Terminal not saved when Bank is saved

Lecture 247 Serializable new Java keyword implements, as in public class Bank implements Serializable {...} Serializable is an interface, not a class Find out about interfaces in cs210 (and a little bit soon) Java 1.5 does a cleaner job with persistence

Lecture 248 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 2410 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 2411 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 2412 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 2413 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 2414 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 2415 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 2416 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 2417 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 2418 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 2419

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

Lecture 2421 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 2422 java Juno -e -g