Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lec 15 Writing an Applet Class. Agenda Writing an Applet class Java Graphics class.

Similar presentations


Presentation on theme: "Lec 15 Writing an Applet Class. Agenda Writing an Applet class Java Graphics class."— Presentation transcript:

1 Lec 15 Writing an Applet Class

2 Agenda Writing an Applet class Java Graphics class

3 Two Ways to Use Java Applet—runs on the web – uses graphical interfaces (usually) – can't access files on local computer – downloaded from website by browser – no main method in class! Application—runs on a local computer – has main method – Can run "stand alone" on local computer – can use graphical or nongraphical interfaces

4 Drawing on Computer Normal vs Computer Graphics Coordinates

5 Simple Drawing Demo Applet import java.applet.*; //so we can extend the Applet class import java.awt.*; //so we can use graphics commands public class DrawDemo extends Applet { public void paint(Graphics g) { //draws a blue oval on the screen g.setColor(new Color(0, 0, 255)); g.fillRect(100,100,30,50); g.setColor(new Color(0, 255, 0)); g.drawLine(115,125, 315,125); g.setColor(new Color(255, 0, 0)); g.drawOval(275, 85, 80, 80); }

6 Java Graphics Class http://download.oracle.com/javase/1.4.2/doc s/api/java/awt/Graphics.html http://download.oracle.com/javase/1.4.2/doc s/api/java/awt/Graphics.html

7 Demo – drawing stick figure Graph Paper can help

8 Write an Applet that draws a house should at least have a window, a door, and a roof. Use different colors and make it look good. Lab15House

9 How to draw a filled Triangle? Arrays are lists of data Use an array of x and y values – Hand them off to g.fillPolygon int [] x = {100, 200, 300}; int [] y = {100, 500, 100}; g.fillPolygon(x,y,3);


Download ppt "Lec 15 Writing an Applet Class. Agenda Writing an Applet class Java Graphics class."

Similar presentations


Ads by Google