Laboratory Study November, 7 2003. Demonstrates Life Cycle of an Applet + Mouse Events + Scrolling.

Slides:



Advertisements
Similar presentations
Made with love, by Zachary Langley Applets The Graphics Presentation.
Advertisements

Life Cycle of an Applet, along with response to mouse events and other simple features. (ps:only two possible examples for life circle of an Applet)
Programming in Java; Instructor:John Punin Graphics and Graphical User Interfaces1 Programming in Java Graphics and Graphical User Interfaces.
Mouse Listeners We continue our examination of GUIs by looking at how to interact with the mouse –Just as Java creates Events when the user interacts with.
Computer Science 209 Graphics and GUIs. Working with Color The class java.awt.Color includes constants for typical color values and also supports the.
Object Oriented Programming Lecture 7: Algorithm animation using strategy and factory patterns, The Adapter design pattern
Inner Classes in Java CMSC 432 Shon Vick. 2 Conceptual Structure package p 1 class A 1 class A 2... class A n... package n class A 1 class A 2... class.
Jan Event Handling -1.1 Yangjun Chen Dept. Business Computing University of Winnipeg.
Slides prepared by Rose Williams, Binghamton University Mouse Events + Chapter 17: Applets.
Event Handling Events and Listeners Timers and Animation.
CS3157 Java UI Recitation. Material Covered: Overview of AWT components, Event Handling, creating applets, and sample UI. Not covered in recitation: Drawing,
Slides prepared by Rose Williams, Binghamton University Chapter 18 Applets.
1 Gui Programming (Part I) Graphical User Interfaces (Part I) l Introduction to events. l A Brief history. l Event sources and listeners. l The delegation.
Lecture 18 Review the difference between abstract classes and interfaces The Cloneable interface Shallow and deep copies The ActionListener interface,
EVENTS CSC 171 FALL 2004 LECTURE 16. “Traditional” Input In console applications, user input is under control of the program The program asks the user.
Mouse Events. Handling Mouse Events Java provides two listener interfaces to handle mouse events: MouseListener;  MouseListener;  MouseMotionListener.
Chapter 11 Java AWT Part I: Mouse Events (Optional) Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin,
Events Chapter Six. Old (procedural) vs. OOPS Programs §OOPS programs react to the users demands §Anytime/anyplace §EVENT = “An Action taken by a user”
Cs884(Prasad)java12AWT1 Abstract Windowing Toolkit Support for Graphical User Interface (Event-driven programming)
CS 11 java track: lecture 4 This week: arrays interfaces listener classes inner classes GUI callbacks.
Java GUI’s are event driven, meaning they generate events when the user interacts with the program. Typical events are moving the mouse, clicking a mouse.
Session 11 Border Layout, using Panels, Introduction to PinBallGame.
Programming and Problem Solving With Java Copyright 1999, James M. Slack Graphics in Java Applications The Graphics Class The Canvas Class The MouseListener.
CSE 501N Fall ‘09 20: Event Handling and Inner Classes 17 November 2009 Nick Leidenfrost.
SD2071 Games Programming Abstraction, inheritance and interfaces Exceptions Two dimensional arrays Java collections framework Files Aaron Kans.
7/3/00SEM107- © Kamin & ReddyClass 11 - Events - 1 Class 11 - Events r A couple of odds & ends m Component sizes  switch statement r Event types r Catching.
Previous programs used a JLabel for OUTPUT. Another Swing component that can be used for both user input and output is the JTextfield. Suppose we want.
– Advanced Programming P ROGRAMMING IN Lecture 21 Introduction to Swing.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
CSC 205 – Java Programming II Applet. Types of Java Programs Applets Applications Console applications Graphics applications Applications are stand-alone.
Copyright © 2002, Systems and Computer Engineering, Carleton University b-Gui2.ppt * Object-Oriented Software Development Part 18-b Building.
CSE 219 Computer Science III Image Manipulation. HW 1 Has been posted on Blackboard Making a Game of Life with limited.
Chapter 7: Pinball Game Construction Kit. Vectors Example of a “collection class” Must “import java.util.Vector” More flexible than arrays: will grow.
Layout Managers Arranges and lays out the GUI components on a container.
CompSci 230 S Software Construction Applets & AWT.
For (int i = 1; i
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
Understand the difference between applets and applications Identify meaningful applet resources for academic subjects Create and demonstrate a basic Java.
CMSC 341 Making Java GUIs Functional. 09/29/2007 CMSC 341 Events 2 More on Swing Great Swing demo at /demos/jfc/SwingSet2/SwingSet2Plugin.html.
Week 6: Basic GUI Programming Concepts in Java Example: JFrameDemo.java container : a screen window/applet window/panel that groups and arranges components.
© Marty Hall, Larry Brown Web core programming 1 Handling Mouse and Keyboard Events.
©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 10: Event Handling 1 Event Handling.
GUI DYNAMICS Lecture 11 CS2110 – Fall GUI Statics and GUI Dynamics  Statics: what’s drawn on the screen  Components buttons, labels, lists, sliders,
©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 10: Event Handling 1 Chapter 10 Event Handling.
Mouse Listeners Moving the mouse will also generate events like the Timer –To have your program respond, you must implement either or both of MouseListener.
Events in JAVA Needed for Applets and GUI based programs. Applet uses GUI to interact with user. Most of the events are generated by Mouse, Keyboard.
CSI 3125, Preliminaries, page 1 AWT Control. CSI 3125, Preliminaries, page 2 AWT Control The AWT supports the following types of controls: ■ Labels ■
1 Event Handling – Lecture 4 Prepared by: Ahmad Ramin Rahimee Assistant Professor ICTI.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 10.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
What Is an Event? Events – Objects that describe what happened Event sources – The generator of an event Event handlers – A method that receives an event.
CSI 3125, Preliminaries, page 1 Event Handling. CSI 3125, Preliminaries, page 2 Event Handling An Event Change in the state of an object is known as event.
CSI 3125, Preliminaries, page 1 Adapter Class. CSI 3125, Preliminaries, page 2 Adapter Class Java provides a special feature, called an adapter class,
GUI Tutorial Day 4. More GUI action  adding a Mouse Listener  SimpleDots  Simple mouse listener  Draw an oval where the mouse is clicked  Box example.
Chapter 14 Applets. Applets: Introduction Java programs are divided into two main categories, applets and applications An application is an ordinary Java.
Java Programming (By Rama Bhadra Rao M) You can Trace me in Day 5
Prepared by: Dr. Abdallah Mohamed, AOU-KW Unit7: Event-driven programming 1.
Chapter 6 Building Java GUIs. MVC Model View Controller The model passes its data to the view for rendering The view determines which events are passed.
Events and Event Handling
Java Applets.
INFSY 547: WEB-Based Technologies
Computer Science 209 Graphics and GUIs.
GUI III IS
CSE Software Engineering Fall 1999 Updated by J. Brown
Introduction to Computing Using Java
GUI Programming using Java - Mouse Events
Java Applets.
Objects At Their Best— Java's Abstract Window Toolkit
Border Layout, using Panels, Introduction to PinBallGame
Making Java GUIs Functional
Presentation transcript:

Laboratory Study November,

Demonstrates Life Cycle of an Applet + Mouse Events + Scrolling

import java.applet.*; import java.awt.*; import java.awt.event.*; public class Simple4 extends Applet implements MouseListener { TextField tField; public void init() ; tField = new TextField (); tField.setEditable(false); tField.addMouseListener(this); //set layout manager to get the widest textfield setLayout (new java.awt.GridLayout(1, 0)); add (tField); addItem ("initializing... "); } public void start() { addItem ("starting... "); } public void stop() { addItem ("stopping... "); }

public void destroy() { addItem ("preparing for unloading..."); } void addItem (String newWord) { System.out.println (newWord); String t = tField.getText(); tField.setText(t + newWord); } / * The paint method is no longer necessary, since * the TextField repaints itself automatically. */ / * Implementation of Mouse Listener interface. * The following empty methods can be removed * by implementing a MouseAdapter (usually done using an inner class). */ public void mouseEntered (MouseEvent event) { } public void mouseExited (MouseEvent event) { } public void mousePressed (MouseEvent event) { } public void mouseReleased (MouseEvent event) { } public void mouseClicked (MouseEvent event) { addItem("click!... "); } }

Another example of Adapter Classes If we use MouseAdapter class instead of MouseListener implementation……

A mouse adapter that beeps when the mouse is clicked : import java.awt.*; import java.awt.event.*; public class MouseBeeper extends MouseAdapter { public void mouseClicked(MouseEvent e) { Toolkit.getDefaultToolkit().beep(); }

Without extending the MouseAdapter class import java.awt.*; import java.awt.event.*; public class MouseBeeper implements MouseListener { public void mouseClicked(MouseEvent e) { Toolkit.getDefaultToolkit().beep(); } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } }

Another complex applet example

Converts temperature Celsius to Fahrenheit within 100 degrees with a scrollbar import java.awt.*; import java.applet.Applet; import java.awt.event.*; public class Temp extends Applet implements AdjustmentListener { private Scrollbar ConvertCelc; //scrollbar named arbitrarily as ConvertCelc private float ConvertCelcValue = 0; //ConvertCelcValue is a float because of the transformation formula public void init() { Label title1; title1 = new Label("degrees C... to... degrees F"); //label scrollbar add(title1); ConvertCelc= new Scrollbar (Scrollbar.HORIZONTAL, 0, 1, 0, 101); add(ConvertCelc); ConvertCelc.addAdjustmentListener (this); } //end init

public void paint(Graphics g) { float cCF; cCF = ((ConvertCelcValue*1.8f) +32); //calculate the conversion g.drawString("Celcius = “ +ConvertCelctValue + “ Fahrenheit =“ +cCF, 0, 75); //draw text } //end paint public void adjustmentValueChanged(AdjustmentEvent e) { ConvertCelcValue = (float) ConvertCelc.getValue(); //slider gets value of conversion and placement of bar repaint(); } //end adujustmentValueChanged } //end all

Assignment Test to draw any polygon Next two slides will help you to draw the shape. Try to read the data from keyboard