Events CSC 171 FALL 2001 LECTURE 9. History: the ABC 1936-1939 John Vincent Atanasoff, with John Berry, developed the machine we now call the ABC -- the.

Slides:



Advertisements
Similar presentations
Lecture 17 Abstract classes Interfaces The Comparable interface Event listeners All in chapter 10: please read it.
Advertisements

June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 1 Lecture 9 Object Oriented Programming in Java Advanced Topics Abstract Windowing.
For Loops & Iterators CSC 171 FALL 2001 LECTURE 7.
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.
Principles of Object-Oriented Software Development The language Java.
Unit 111 Event-Driven Programming Listener or Event handler Example: Handling Button Events Example: Handling Mouse Events Example: Handling Keyboard Events.
Event-Driven Programming
CS3157 Java UI Recitation. Material Covered: Overview of AWT components, Event Handling, creating applets, and sample UI. Not covered in recitation: Drawing,
Lecture 19 Graphics User Interfaces (GUIs)
James Tam An introduction into HCI: Task-Centered System Design An Introduction To Graphical User Interfaces The event-driven model Building a simple.
Scoping and Recursion CSC 171 FALL 2001 LECTURE 8.
1 Class 8. 2 Chapter Objectives Use Swing components to build the GUI for a Swing program Implement an ActionListener to handle events Add interface components.
Io package as Java’s basic I/O system continue’d.
CSTP WS00CS423 (cotter)1 Java Applets Objective: Learn how to develop Java programs that interact with users through a Web browser.
Applets CS 3331 Sections 3.3 & 4.7 of [Jia03].
JAVA, JAVA, JAVA Object-Oriented Problem Solving Ralph Morelli Trinity College Hartford, CT presentation slides for published by Prentice Hall Second Edition.
11/9: Recursion, Method Overloading About Scoping.java Recursion Method overloading.
Lesson 36: The calculator – Java Applets. 1. Creating Your First Applet HelloWorldApp is an example of a Java application, a standalone program. Now you.
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.
GUI programming Graphical user interface-based programming.
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,
CS 11 java track: lecture 4 This week: arrays interfaces listener classes inner classes GUI callbacks.
Java Event Handling CSIS 3701: Advanced Object Oriented Programming.
Event Handling Mohanraj S AP / IT Angel College of Engg & Tech.,
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.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Object-Oriented Programming (Java), Unit 18 Kirk Scott 1.
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
12/5/00SEM107, Kamin & ReddyReview - 34 Events Event types Catching different event types Getting information from components and events Distinguishing.
Java Applet Basics (2). The Body Mass Index Calculator.
A simple swing example GETTING STARTED WITH WIND CHILL.
1 GUI programming Graphical user interface-based programming Chapter G1 (pages )
GUI DYNAMICS Lecture 11 CS2110 – Fall GUI Statics and GUI Dynamics  Statics: what’s drawn on the screen  Components buttons, labels, lists, sliders,
Practical Session 10: Animation. Animation kinds There are three basic kinds of animation: 1. Moving object 2. Changing pictures 3. Combination of 1 and.
1 Applications & Applets Standalone applications & Java applets Peter Mozelius DSV/UCSC.
Java the UML Way versjon Only to be used in connection with the book "Java the UML Way", by Else Lervik and.
PHY281 Scientific Java Programming ArraysSlide 1 Arrays In this section we will learn how about storing groups of related variables that share the same.
A cannon game ?. Simple version angle from command line, one shot only Coordinate system is “upside-down”: Use dy(int) method to transform y coordinate:
CSI 3125, Preliminaries, page 1 Applet. CSI 3125, Preliminaries, page 2 Applet An applet is a Java program that runs in a Web browser. An applet can be.
עקרונות תכנות מונחה עצמים תרגול 7: אנימציה. בשבוע שעבר  paint  Graphics  repaint.
Event-Driven Programming F Procedural programming is executed in procedural order. F In event-driven programming, code is executed upon activation of events.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 10.
CSI 3125, Preliminaries, page 1 Adapter Class. CSI 3125, Preliminaries, page 2 Adapter Class Java provides a special feature, called an adapter class,
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,
Object Oriented Programming in Java Habib Rostami Lecture 10.
JAVA, JAVA, JAVA Object-Oriented Problem Solving Ralph Morelli Trinity College Hartford, CT presentation slides for published by Prentice Hall Second Edition.
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.
Lecture 8.5 Animating with EventTimer. © 2006 Pearson Addison-Wesley. All rights reserved A Crash Course in the Use of Timed Events What kinds of.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Lecture 15.1 Event Delegation.
Modular Event Handling
Introduction Many Java application use a graphical user interface or GUI (pronounced “gooey”). A GUI is a graphical window or windows that provide interaction.
CSC 205 Programming II Lecture 5 AWT - I.
Java Applet What is a Java Applet? How is applet compiled?
Lecture 09 Applets.
Ellen Walker Hiram College
MVC Paradigm The MVC paradigm breaks applications or interfaces into three parts: the model, the view, and the controller. A --> 25 % B --> 60 % C -->
Systems of Computation
Inner Classes 11/14/ Dec-04 inner_classes.ppt.
Graphical user interface-based programming
TO COMPLETE THE FOLLOWING:
עקרונות תכנות מונחה עצמים תרגול 7: אנימציה
class PrintOnetoTen { public static void main(String args[]) {
어서와 Java는 처음이지! 제13장 실전프로젝트.
Constructors, GUI’s(Using Swing) and ActionListner
CiS 260: App Dev I Chapter 6: GUI and OOD.
עקרונות תכנות מונחה עצמים תרגול 7: אנימציה
Presentation transcript:

Events CSC 171 FALL 2001 LECTURE 9

History: the ABC John Vincent Atanasoff, with John Berry, developed the machine we now call the ABC -- the Atanasoff- Berry Computer -- at Iowa State University. A special purpose machine for the solution to sets of linear equations Perhaps the earliest example of an electronic calculator

Methods Does this work? public class myClass { public static void main(String args[]){ double x = 3.0; double y = mySquare(x); System.out.println(x+“^2 ==“ + y); } public static int mySquare(int x) { return x * x; } }

Methods Does this work? public class myClass { public static void main(String args[]){ int x = 3; int y = mySquare(x); System.out.println(x+“^2 ==“ + y); } public static double mySquare(double x) { return x * x; } }

Method overloading Does this work? public class myClass { public static void main(String args[]){ int x = 3; int y = mySquare(x); System.out.println(x+“^2 ==“ + y); double z = 3.0; double k = mySquare(k); System.out.println(z+“^2 ==“ + k); } public static int mySquare(int x) { return x * x; } public static double mySquare(double x) { return x * x; } }

Method Overloading Methods of the same name can have different sets of parameters. – In reality the compiler mangles the name (combines it with it’s parameters)

Method overloading public class myClass { public static void main(String args[]){ int x = 3; int y = myPlus(x); int z = myPlus(x,y); System.out.println(“z == “ + z); } public static int myPlus(int x) { return x + 1; } public static int myPlus(int x, int y) { return x + y; } }

Method overloading Often useful in constructors public class Student { private String studentName; private int studentNumber; public Student(String name; int number){ studentName=name; studentNumber = number; } public Student() { // The generic student studentName=“J Doe”; studentNumber = ; }

Events Often, we have applications that begin at the beginning, proceed step by step, and stop at the end Increasingly, however, we have programs that wait around to respond to environmental events. So, we have event handlers

“Listening” for “Actions” “Waiting” for “Events” In JAVA we have “actionListeners” ActionListeners listen for “actionEvents”

An ActionListener ActionListener is an interface in JAVA In order to implement an actionlistener, we have to write the method to handle the event public void actionPerformed(actionEvent e)

Set up import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class appLec extends Applet implements ActionListener{ Label promptLabel; Button doIt; int value = 0 ; String promptString = "Value is == ";

initialzation public void init() { promptLabel = new Label(promptString + value); add(promptLabel); doIt = new Button("DO IT!!"); doIt.addActionListener(this); add(doIt); }

The actionListener public void actionPerformed(ActionEvent e) { value++; promptLabel.setText(promptString + value); }

Distinguishing source import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class appLec2 extends Applet implements ActionListener{ Label promptLabel; Button b1,b2; // two possible sources of events int value = 0 ; String promptString = "Value is == ";

initilization public void init() { promptLabel = new Label(promptString + value); add(promptLabel); b1 = new Button("INCREMENT"); b1.addActionListener(this); add(b1); b2 = new Button("DECREMENT"); b2.addActionListener(this); add(b2); }

ActionListener public void actionPerformed(ActionEvent e) { if (e.getSource() == b1) { value++;} if (e.getSource() == b2) { value--;} // “else” ok promptLabel.setText(promptString + value); }

Events: The soul of animation import java.applet.Applet; public class appLec3 extends Applet { int x = 100, y=100, inc_x = 1, inc_y = 1, size = 30 ; public void paint(Graphics g) { g.fillOval(x,y,size,size); if ((y 251)) inc_y *= -1 ; if ((x 473)) inc_x *= -1 ; x += inc_x; y += inc_y; repaint(); }