Example: CharCheck. That s It??! What do you imagine happens after main() finishes?

Similar documents
COMP-202 Unit 10: Basics of GUI Programming (Non examinable) (Caveat: Dan is not an expert in GUI programming, so don't take this for gospel :) )

Graphical User Interfaces (GUIs)

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

Swing. By Iqtidar Ali

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

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

SD Module-1 Advanced JAVA

SD Module-1 Advanced JAVA. Assignment No. 4

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming

Packages: Putting Classes Together

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

Window Interfaces Using Swing Objects

MIT AITI Swing Event Model Lecture 17

Systems Programming Graphical User Interfaces

Widget Toolkits CS MVC

Swing from A to Z Some Simple Components. Preface

Programming Languages and Techniques (CIS120e)

MODEL UPDATES MANIPULATES USER

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

Page 1. Human-computer interaction. Lecture 2: Design & Implementation. Building user interfaces. Users and limitations

Example Programs. COSC 3461 User Interfaces. GUI Program Organization. Outline. DemoHelloWorld.java DemoHelloWorld2.java DemoSwing.

Graphical User Interfaces. Comp 152

Window Interfaces Using Swing Objects

Programming Language Concepts: Lecture 8

GUI Program Organization. Sequential vs. Event-driven Programming. Sequential Programming. Outline

Java & Graphical User Interface II. Wang Yang wyang AT njnet.edu.cn

Graphical User Interface (GUI)

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver

CSC207 Week 4. Larry Zhang

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

AS COMPUTERS AND THEIR USER INTERFACES have become easier to use,

JRadioButton account_type_radio_button2 = new JRadioButton("Current"); ButtonGroup account_type_button_group = new ButtonGroup();

Lecture 3: Java Graphics & Events

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

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!

AP CS Unit 11: Graphics and Events

COMPSCI 230. Software Design and Construction. Swing

SINGLE EVENT HANDLING

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

Critical Thinking Assignment #6: Java Program #6 of 6 (70 Points)

Starting Out with Java: From Control Structures Through Objects Sixth Edition

Graphic User Interfaces. - GUI concepts - Swing - AWT

Java. GUI building with the AWT

Lecture 5: Java Graphics

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

CS Exam 1 Review Suggestions

First Name: AITI 2004: Exam 2 July 19, 2004

Page 1. Human-computer interaction. Lecture 1b: Design & Implementation. Building user interfaces. Mental & implementation models

Introduction to Computer Science I

CS211 GUI Dynamics. Announcements. Motivation/Overview. Example Revisted

Introduction to concurrency and GUIs

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

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

Java Graphical User Interfaces AWT (Abstract Window Toolkit) & Swing

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

14.2 Java s New Nimbus Look-and-Feel 551 Sample GUI: The SwingSet3 Demo Application As an example of a GUI, consider Fig. 14.1, which shows the SwingS

CSC 1214: Object-Oriented Programming

First Name: AITI 2004: Exam 2 July 19, 2004

Java IDE Programming-I

RAIK 183H Examination 2 Solution. November 11, 2013

Multiple Choice Questions: Identify the choice that best completes the statement or answers the question. (15 marks)

Swing: Building GUIs in Java

Swing: Building GUIs in Java

DEMYSTIFYING PROGRAMMING: CHAPTER SIX METHODS (TOC DETAILED) CHAPTER SIX: METHODS 1

CS 335 Java Programming Controls. Fall 2007

GUI Applications. Let s start with a simple Swing application in Java, and then we will look at the same application in Jython. See Listing 16-1.

Method Of Key Event Key Listener must implement three methods, keypressed(), keyreleased() & keytyped(). 1) keypressed() : will run whenever a key is

Part I: Learn Common Graphics Components

BM214E Object Oriented Programming Lecture 13

Original GUIs. IntroGUI 1

Graphical Applications

Graphical interfaces & event-driven programming

Widgets. Widgets Widget Toolkits. User Interface Widget

Widgets. Widgets Widget Toolkits. 2.3 Widgets 1

Introduction. Introduction

Name: Checked: Learn about listeners, events, and simple animation for interactive graphical user interfaces.

Hanley s Survival Guide for Visual Applications with NetBeans 2.0 Last Updated: 5/20/2015 TABLE OF CONTENTS

An array is a type of variable that is able to hold more than one piece of information under a single variable name.

GUI in Java TalentHome Solutions

Graphical User Interface (GUI)

Client-side GUI. A simple Swing-gui for searching for proudcts

The AWT Event Model 9

Commands. Written commands can be reused, cataloged, etc. Sometimes they also contain "undo" commands, too.

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling

Java Help Files. by Peter Lavin. May 22, 2004

DEMYSTIFYING PROGRAMMING: CHAPTER FOUR

CS 11 java track: lecture 3

Chapter 12 GUI Basics

2110: GUIS: Graphical User Interfaces

Lecture (06) Java Forms

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

Dr. Hikmat A. M. AbdelJaber

Abstract, Interface, GUIs. Ch. 11 & 16

CS 106A, Lecture 23 Interactors and GCanvas

7. Program Frameworks

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

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

Datenbank-Praktikum. Universität zu Lübeck Sommersemester 2006 Lecture: Swing. Ho Ngoc Duc 1

Charlie Garrod Michael Hilton

Transcription:

Event-Driven Software Paradigm Today Finish Programming Unit: Discuss Graphics In the old days, computers did exactly what the programmer said Once started, it would run automagically until done Then you could look at the output It was great! All that work it did, so you didn t have to Event-driven systems But Events are Important Too Nowadays, interactivity is important Most software does not run autonomously Even though it used to be the norm Instead, it interacts, with people other software When was the last time you ran a program that was not interactive? Events: requests to interact Events come from outside the program Users can click Other programs can make requests Can you think of an example? Interactive systems respond to events Example: A Java window that sits there doing nothing until you click, type, etc. Have you seen one like that? Java is Event Oriented Java GUIs are normally event driven A Java GUI waits for an event to occur The event makes an event handler run The event handler does something Your program does not call the event handler! So how does the event handler get called? Who calls the event handler? There is a program called java.exe It sets up a JRE (means?) The computer knows when you click The JRE talks with the computer and finds out that you clicked (typed,) JRE then bundles info into an object calls an event handler gives the event handler the object 1

Example: CharCheck //(D. Berleant) import java.lang.*; import java.io.*; import java.awt.*; //swing only //obsoletes some of this import java.awt.event.*; //swing only obsoletes //some of above line import javax.swing.*; public class CharCheck{ static Frame f; //swing version: JFrame f; public static void main (String args[ ]){ DoSomething d=new DoSomething( ); TextField t; /*swing version: JTextField t; JtextField is defined in javax.swing */ t=new TextField("Initial text"); //swing version: //t=new // JTextField // ("Initial text"); //Event handlers are in //java.awt.event... t.addactionlistener(d); t.addkeylistener(d); f=new Frame("Hello, I am" + "a Frame"); //swing version: //f=new JFrame // ("Hello, I am" + // "a Frame"); f.setsize(800,500); //Color is in java.awt f.setbackground(color.orange); // swing version: // setbackground // (Color.orange); f.add("north",t); // swing version // add("north",t); That s It??! What do you imagine happens after main() finishes? 2

Java Programs Hanging Around Not! up to no gooddrinking beercausing trouble They wait for events JRE finds out about it from OS JRE sends program a data object The program reacts to the event It is event driven Event Driven Programming Let s look at: the event driven part of the CharCheck program Recall part of it public class CharCheck{ static Frame f; //swing version: JFrame f; public static void main (String args[ ]){ DoSomething d=new DoSomething( ); Part we ve seen + 2 new lines f.add("north",t); // swing version // add("north",t); The new stuff, continued public void actionperformed (ActionEvent e){ System.out.println (e.getactioncommand( )); //runs after typing the return key 3

The new stuff, continued public void keypressed(keyevent k){ System.out.println ("next char is " +(char)(1+k.getkeychar( ))); //runs when a key is pressed The new stuff (end) public void keyreleased(keyevent k){ System.out.println ("number of char is " +(int)k.getkeychar( )); //runs when a key is released Where does output go? Output is to (1) a frame, and (2) the window from which the program was run Initial display on next slide After typing in some characters: System.out.println( ) output is: 4

System.out.println( ) output is:.. A few more comments on Event Handlers We needed two: Can't extend (inherit) more than one, so the other must say implements (it s an interface) Java (JRE) knows what method to call when an event occurs That is why all interface method prototypes must be implemented A few more comments on Event Handlers We needed two: Can't extend (inherit) more than one, so the other must say implements (it s an interface) Java (JRE) knows what method to call when an event occurs That is why all interface method prototypes must be implemented AWT= "Abstract Windowing Toolkit" Contains many "heavyweight" components Component: a GUI item (buttons, text fields...) Heavyweight: refers to a GUI item that relies on the platform-provided windowing capabilities Problem: a Button looks different on Macs, and MS systems - Java tries to be platform-independent! Lightweight: refers to a platform-independent GUI component Example: a JButton is lightweight Swing Has (mostly) lightweight components Used to be "experimental" Hence, import javax.swing.*; The "x" indicated it was experimental...so, why is the "x" still there?? If you use swing, must also import awt There are more swing than awt components Example: TextField JTextField JPasswordField (no "PasswordField" class exists) - a JPasswordField is like a JTextField but doesn't show what characters are typed AWT vs. Swing 5