Creating an Object that can draw itself The paint method can ‘draw’ because it is passed a graphics environment as a parameter. If a class method is passed.

Slides:



Advertisements
Similar presentations
Applets Graphical Java programs Run inside web browser Platform-neutral Easy deployment--loads when needed Secure.
Advertisements

Java Applets. An applet is a Panel that allows interaction with a Java program. A applet is typically embedded in a Web page and can be run from a browser.
Object Oriented Programming with Java (150704).   Applet  AWT (Abstract Window Toolkit)  Japplet  Swing Types of Applet.
Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Applets. The Applet Class public class MyApplet extends java.applet.Applet {... /** The no-arg constructor is called by the browser when the Web page.
Review of Java Applets Vijayan Sugumaran Decision and Information Sciences Oakland University.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 16 Applets.
18-Jun-15 Applets. 2 An applet is a program that is typically embedded in a Web page and can be run from a browser You need special HTML in the Web page.
1 Recitation 11. Applet Applets. An applet is a Java program that is started by a browser (e.g. netscape or internet explorer) when an html file has a.
Applets, Graphical User Interfaces, and Threads / Chapter 9 1 Applets, Graphical User Interfaces, and Threads.
Applet class The Applet class provides the essential framework that enables applets to be run by a web browser Applet do not have main method Applet depend.
Applets. An applet is a Panel that allows interaction with a Java program A applet is typically embedded in a Web page and can be run from a browser You.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 14 Applets, Images,
APPLETS CSC 171 FALL 2004 LECTURE 6. APPLETS Graphical Java programs Run inside web browser Platform-neutral Easy deployment--loads when needed Secure.
Unit 071 Review of Applets Learning Outcomes oDistinguish between Java Applications and Java Applets. oWrite applet programs that can load images and play.
26-Jun-15 Applets. 2 An applet is a Panel that allows interaction with a Java program A applet is typically embedded in a Web page and can be run from.
28-Jun-15 Applets. 2 An applet is a program that is typically embedded in a Web page and can be run from a browser You need special HTML in the Web page.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L05 (Chapter 16) Applets.
CSTP WS00CS423 (cotter)1 Java Applets Objective: Learn how to develop Java programs that interact with users through a Web browser.
Applets  The Applet Class  The HTML Tag F Passing Parameters to Applets.
Applets Java API.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 16: Java Applets & AWT Fundamentals of Web Programming.
Agenda For Feb Finish up Unit 3 Exercises on page Unit 4 Exercises on page 33. Question #2 3. Create a Happy Face Java Applet (due next class).
Applets CS 3331 Sections 3.3 & 4.7 of [Jia03].
Internet Software Development Applets Paul J Krause.
Applets.
JAPPLET.
Applets Life Cycle Drawing and Event Handling Methods for UI Components Applet Capabilities Example.
COP 4331 – OOD&P Lecture 6. Review Midterm Review Complete sample application –See SwingColorTest.java.
Object Oriented Programming Lecture 4: Refactoring, An Applet Example, Idiom - Animation applets, Introduction to the Laboratorial exercise www2.hh.se/staff/jebe/oop2005/
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Introduction to Applets Course Lecture Slides 29 th July 2010.
Java Applets. Topics What is an applet? To convert GUI applications to Applets Hello World applet example!! Applets life cycle examples Invoking applets.
Chapter 10: Applets and Advanced Graphics The Applet Class The Applet Class The HTML Tag The HTML Tag Passing Parameters to Applets Passing Parameters.
Java Threads. What is a Thread? A thread can be loosely defined as a separate stream of execution that takes place simultaneously with and independently.
Canvas and Graphics CS 21a. 9/26/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L17: Canvas.
Java Applets. An applet is a Panel that allows interaction with a Java program. A applet is typically embedded in a Web page and can be run from a browser.
Applets. What is an applet? Why create applets instead of applications? – Applets are Java programs that can be embedded in an HTML document – In contrast,
Review of CIS 120 Concepts: What you said you want….
2/4: Objects & Java Applets Objects: their nature –attributes & behaviors –inheritance Java Applets –what is an applet vs. an application? –where do applets.
Applets. An applet is a Panel that allows interaction with a Java program A applet is typically embedded in a Web page and can be run from a browser You.
Java Applets 1. What is an applet? An applet is a small Java program that is typically embedded in a Web page and can be run using the applet viewer or.
CSC 205 – Java Programming II Applet. Types of Java Programs Applets Applications Console applications Graphics applications Applications are stand-alone.
Pravin Yannawar, DOCS, NMU Jalgaon Basic Java : Applets 2 Objectives of This Session Identify the need for Applets Distinguish between Applets and Applications.
Program that runs in appletviewer (test utility for applets) Web browser (IE, Communicator) Executes when HTML (Hypertext Markup Language) document containing.
Arrays Construct array: new double[10] Store in variable of type double[] double[] data = new double[10];
Chapter 6 Applets and HTML  Overview  HTML tags for Applets  Applet Life Cycle  Applet Class  JAR files.
APPLET. 2 Introduction to Java Applet Programs Applications are stand alone programs ◦ executed with Java interpreter Applet is a small program ◦ can.
Chapter 14 Applets and Advanced GUI  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets F.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Chapter 8 (Horstmann’s Book) Frameworks Hwajung Lee.
1 Applets are small applications that are accessed on an Internet server, transported over the internet, automatically installed and run as a part of web.
Chapter 8 Frameworks. Frameworks Framework is a set of cooperating classes and interface types that structures the essential mechanisms of a particular.
Applets, Images, and Audio Chapter 14 CSCI CSCI 1302 – Applets, Images, and Audio2 Outline Introduction The Applet Class –The init Method –The start.
CSI 3125, Preliminaries, page 1 Applet. CSI 3125, Preliminaries, page 2 Graphics Methods public abstract void drawString(String str, int x, int y): is.
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.
CHAPTER Agenda Applets Servelets Browsers HelloWorld.
1 Java Applet Basics Chapter Eight. 2 Applets vs. Applications l Applications: Stand alone Java programs run by interpreter l Applets WWW browser embedded.
Methods Chapter 6. 2 Program Modules in Java What we call "functions" in C++ are called "___________________" in Java Purpose –Reuse code –Modularize.
CS202 Java Object Oriented Programming GUI Programming – Applets Chengyu Sun California State University, Los Angeles.
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.
30 Java Applets.
Systems of Computation
UNIT-5.
Applet in Java.
Java Programming COMP-417 Applet
Applet Fundamentals Applet are small applications that are accessed on an Internet server, transported over the Internet, automatically installed and run.
11.1 Applets & graphics.
JAVA APPLET PREPARED BY Mr. Jahanzaib Ahmed
APPLET PROGRAMMING.
Presentation transcript:

Creating an Object that can draw itself The paint method can ‘draw’ because it is passed a graphics environment as a parameter. If a class method is passed a graphics environment (ie. object of type Graphics or Graphics2D), then the method can draw also. eg.) public void xxx (Graphics g){ g.drawRect(10,10, 200,150); }

Suppose we have a class Dog…

and we want to provide one more behavior……… we want to be able to draw a Dog object. The draw method will need a Graphics environment if it is going to draw………….

File DogApplet.java import java.applet.Applet; import java.awt.Graphics; //An applet that draws two Dogs public class DogApplet extends Applet { public void paint(Graphics g){ Dog myDog = new Dog(“Spot”,“beagle”); myDog.setAge(10); Dog yourDog = new Dog(“Rufus”); myDog.draw(g); yourDog.draw(g); }

File Dog..java import java.awt.Graphics; public class Dog{ //regular class constructors and methods public void draw(Graphics g) { int x = 50; int y = 50; //draw start position g.drawOval(x,y,100,50); g.drawOval(x+12,y+12,5,5); //eyes g.drawOval(x+25,y+12, 5,5); g.fillOval(x+16,y+25, 10,10); //nose g.fillOval(x+62,y+13,50,75); //left ear } what happens when we draw 3 dogs???

File Dog..java import java.awt.Graphics; public class Dog{ private int x; //drawing position private int y; public void draw(Graphics g) { g.drawOval(x,y,100,50); g.drawOval(x+12,y+12,5,5); //eyes g.drawOval(x+25,y+12, 5,5); g.fillOval(x+16,y+25, 10,10); //nose g.fillOval(x+62,y+13,50,75); //left ear } Add position to the class data. how does this position get initialized???

import java.awt.Graphics; public class Dog{ // other instance variables private int x; //drawing position private int y; public Dog(String nm, int xpos, int ypos){ nm = name; x = xpos; y = ypos; } public void draw(Graphics g) { …. } Constructor for Dog accepts start position for drawing ……

Updated …File DogApplet.java import java.applet.Applet; import java.awt.Graphics; //An applet that draws two Dogs public class DogApplet extends Applet { public void paint(Graphics g){ Dog myDog = new Dog(“Spot”,“beagle”, 100,100); myDog.setAge(10); Dog yourDog = new Dog(“Rufus”, 300,50); myDog.draw(g); yourDog.draw(g); }

look at implementation………….. DogN.java, DogAppN.java………

What if our draw method needed to be more elaborate, and use Ellipse2D.Double, or Rectangle2D.Double?? 2 solutions………

Typical methods which can be overridden in Applet.. void paint (Graphics g) -- we know this void init() – called once by the applet container when the applet is loaded for execution Typical actions are to initialize fields, create GUI components, load sounds and images

Typical methods which can be overridden in Applet.. void start() – called after init. If the browser visits another website and returns, method start is called again. This method performs any tasks that must be performed when the applet is ‘restarted’

Typical methods which can be overridden in Applet.. void stop() - called when the applet should stop executing – usually when the user of the browser leaves the page. Any tasks that are required to suspend the applet’s execution are done here

Typical methods which can be overridden in Applet.. void destroy() - called when the applet is being removed from memory, usually when browser close. Any tasks needed to release resources are done here.