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)

Slides:



Advertisements
Similar presentations
COMP 110: Introduction to Programming Tyler Johnson Apr 20, 2009 MWF 11:00AM-12:15PM Sitterson 014.
Advertisements

Podsumowanie Nguyen Hung Son Uniwersytet Warszawski.
Custom Painting Gestione della Grafica customizzata Vedi anche:
1 Applets Programming Enabling Application Delivery Via the Web.
Applets and Graphics.
TEMPERATURE CONVERSION
Rectangles moving and responding to the mouse. We want a window with a pile of rectangles in it When we click a rectangle it changes from filled to unfilled.
Variables Conditionals Boolean Expressions Conditional Statements How a program produces different results based on varying circumstances if, else if,
Engr 691 Special Topics in Engineering Science Software Architecture Spring Semester 2004 Lecture Notes.
Chapter 15 Graphics. To paint, you need to specify where to paint. Each component has its own coordinate system with the origin (0, 0) at the upper-left.
Copyright 2010 by Pearson Education Building Java Programs More Graphics reading: Supplement 3G.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
Windowsun Grafik Kullanıcı Arabirimi GUI. Graphical User Interfaces.
Made with love, by Zachary Langley Applets The Graphics Presentation.
Web Design & Development Lecture 19. Java Graphics 2.
1 More on Applets Overview l Changing Colors l Changing Fonts & Styles l Applet Life-Cycle l Input using Dialog Window l Input using HTML parameters l.
Programming in Java; Instructor:John Punin Graphics and Graphical User Interfaces1 Programming in Java Graphics and Graphical User Interfaces.
CSE 1341 Honors Professor Mark Fontenot Southern Methodist University Note Set 21.
Graphics and event-driven programs Learning objectives By the end of this lecture you should be able to: identify and use some of the common components.
Polymorphism Method overriding Method overloading Dynamic binding 1.
Java Applets:. How Applets differ from application?: They do not use main method but init(), start() and paint() methods of the applet class They can.
Object Oriented Programming one of the main reasons we now teach Java instead of C++. C++ was designed to be backwardly compatible with the original.
 Specifies a set of methods (i.e., method headings) that any class that implements that interface must have.  An interface is a type (but is not a class).
Laboratory Study II October, Java Programming Assignment  Write a program to calculate and output the distance traveled by a car on a tank of.
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.
Graphics You draw on a Graphics object The Graphics object cannot directly be created by your code, instead one is generated when the method paintComponent.
Graphics Chapter 16.  If you want to draw shapes such as a bar chart, a clock, or a stop sign, how do you do it?
PHY-102 SAPIntroductory GraphicsSlide 1 Introductory Graphics In this section we will learn how about how to draw graphics on the screen in Java:  Drawing.
LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class.
CSE 341, S. Tanimoto Java-PolyDraw- 1 A Java Case Study: An Applet for Drawing Polygons Motivation -- See a number of AWT features integrated. Get ideas.
Problem Solving 6 GUIs and Event Handling ICS-201 Introduction to Computing II Semester 071.
Graphical User Interfaces, 2D Graphics & Game Programming.
Chapter 5 Programming Graphics. Chapter Goals To be able to write simple applications To display graphical shapes such as lines and ellipses To use colors.
Chapter 5 Programming Graphics. Chapter Goals To be able to write applications with simple graphical user interfaces To display graphical shapes such.
Bar Graph Design. Left-side/Right-side mechanical processing creative, abstract reasoning.
TCU CoSc Programming with Java Handling Events.
Objects, Variables & Methods Java encapsulates data and action modules that access the data in one container, called an object. Object members that.
Jan Event Handling -1.1 Yangjun Chen Dept. Business Computing University of Winnipeg.
Event Handling Events and Listeners Timers and Animation.
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.
Using Java to Illustrate Graph Theory concepts Carol E. Wolf Computer Science Department Pace University.
Object Oriented Programming (OOP) LAB # 5 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal.
Program Design With Methods And Graphics / Chapter 4 1 Abstract Window Toolkit.
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,
Java Applet Presented by Fitsum Okubu. Introduction Introduction Graphics Graphics Methods and Variables Methods and Variables Events Events Decision.
Events Chapter Six. Old (procedural) vs. OOPS Programs §OOPS programs react to the users demands §Anytime/anyplace §EVENT = “An Action taken by a user”
Java Applets. Topics What is an applet? To convert GUI applications to Applets Hello World applet example!! Applets life cycle examples Invoking applets.
Programming and Problem Solving With Java Copyright 1999, James M. Slack Graphics in Java Applications The Graphics Class The Canvas Class The MouseListener.
Applets & Graphics. Applets programs that run inside a browser Java platform-independence makes applets possible security restrictions: –cannot read or.
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.
Lecture 8.3 The Use of JComponent. © 2006 Pearson Addison-Wesley. All rights reserved More About the Standard Drawing Classes java.awt.Container.
– 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.
MSc Workshop - © S. Kamin, U.Reddy Lect 4 - Events - 1 Lecture 4 – Event Handling r Painting r Event types r Catching different event types.
12/5/00SEM107, Kamin & ReddyReview - 34 Events Event types Catching different event types Getting information from components and events Distinguishing.
Layout Managers Arranges and lays out the GUI components on a container.
© 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.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Painting (Chapter 12) Java Certification Study Group January 25, 1999 Mark Roth.
Laboratory Study November, Demonstrates Life Cycle of an Applet + Mouse Events + Scrolling.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 10.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Event Handling H_Func(Event) { } Event Receiver Object Source Object Registration.
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.
10/20/2005week71 Graphics, mouse and mouse motion events, KeyEvent Agenda Classes in AWT for graphics Example java programs –Graphics –Mouse events –Mouse.
Applet: An applet is a java program that is transmitted over the network from the server to client & executed within clients browser. Applets are used.
Mouse Event Handling in Java (Review)
Lecture 09 Applets.
Presentation transcript:

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)

Demonstrating the Life Cycle of an Applet: Simple0

import java.applet.*; import java.awt.*; import java.awt.event.*; public class Simple0 extends Applet { StringBuffer buffer; public void init() { buffer = new StringBuffer(); 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); buffer.append(newWord); repaint() }

public void paint(Graphics g) { g.setColor(new Color(200, 1, 200)); g.drawRect(0, 0, getSize().width - 1, getSize().height - 1); //Draw the current string inside the rectangle g.setColor(Color.blue); g.drawString(buffer.toString(), 5, 15); }

Demonstrates Life Cycle of an Applet + Mouse Events: Simple1

import java.awt.*; import java.awt.event.*; public class Simple1 extends Applet { StringBuffer buffer; public void init() { addMouseListener(new Bob()); buffer = new StringBuffer(); 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); buffer.append(newWord); repaint(); }

public void paint(Graphics g) { g.setColor(new Color(200, 1, 200)); g.drawRect(0, 0, getSize().width - 1, getSize().height - 1); g.setColor(Color.blue); g.drawString(buffer.toString(), 5, 15); } private class Bob implements MouseListener { 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!... "); }

Three simple applet examples

A method which returns the volume of a cube import java.awt.*; import java.applet.Applet; public class volume extends Applet { public void paint(Graphics g) { float answer = areaCube(7,4,2); g.drawString("Area of cube is " +answer, 100, 100); } private float areaCube(float height, float width, float depth) { float area = height*width*depth; return area; }

Draws a circle based on a given center position and radius import java.awt.*; import java.applet.Applet; public class DrawCircle extends Applet { public void paint(Graphics g) { circle(g, 150, 135, 120); //call circle function } //end function //function draws a circle private void circle(Graphics g, int xCentre, int yCentre, int radius) { int horiz = xCentre - radius; //finds starting horizon. position int vert = yCentre - radius;//finds starting vertical position int diameter = radius * 2;//finds diameter g.drawOval(horiz, vert, diameter, diameter); } //end function }

Drawing Houses import java.awt.*; import java.awt.event.*; import java.applet.*; public class drawHouse extends Applet { public void paint(Graphics g) { int wall=50; //allows you to change the size of the house and have them still be 10 pixels apart drawStreet(g,wall,20,100); drawStreet(g,wall,20+wall+10,100); drawStreet(g,wall,20+wall*2+20,100); drawStreet(g,wall,20+wall*3+30,100); } private void drawStreet(Graphics g, int wallHeight, int bottomX, int bottomY) { g.drawRect(bottomX, bottomY, wallHeight, wallHeight); g.drawLine(bottomX+wallHeight, bottomY, bottomX+wallHeight/2, bottomY-wallHeight/2); g.drawLine(bottomX+wallHeight/2, bottomY-wallHeight/2, bottomX, bottomY); } }

A more 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