Title: Abstract Window Toolkit
1Abstract Window Toolkit
2Abstract Window Toolkit
- class library
- graphics
- lines
- rectangles
- circles
- GUI
- text boxes
- labels
- command buttons
3Java Application
- javac SomeApp.java
- java SomeApp
compiling
executing
4Java Application
- execution starts with main
public static void main(String args )
5Java Applet
- javac SomeApplet.java
- appletviewer SomeApplet.html
compiling
executing
machine code
html source
appletviewer
6Java Applet
- execution starts with the browser / appletviewer
- browser / appletviewer loads the .class file
7Appletviewer
- executes applet
- utility to test applets
- included with J2SDK
8Java Applet
keyword
public class Intersection extends Applet
class name
base class
class Intersection inherits from base class Applet
9Java Applet
java applet has the following methods
public void init()
public void start()
public void paint(Graphics g)
public void stop()
public void destroy()
10Java Applet
public void init()
- first method called by the browser or appletviewer
11Java Applet
public void paint(Graphics g)
12HyperText Markup Language (HTML)
width of display area
Class name.html
- lthtmlgt
- ltapplet code class name.class widthwidth
heightheightgt - lt/appletgt
- lt/htmlgt
name of class
width of display area
13Java Applet
the following must exist before executing an
applet
- className.html
- className.java
- className.class
14Intersection Example(Intersection.java)
- import java.awt.
- import java.applet.Applet
- public class Intersection extends Applet
- public void paint(Graphics g)
-
- //draws line from (0,0) to (300,200)
- g.setColor(Color.black)
- g.drawLine( 0, 0, 300, 200)
- //draws line from (300, 0) to (0, 200)
- g.setColor(Color.blue)
- g.drawLine( 300, 0, 0, 200)
-
-
15Graphics
- setColor()
- drawLine()
- drawRect()
- drawString()
16setColor
sets color
- g.setColor(Color.black)
- where g is the object
17drawLine()
g.drawLine(
start point x-coordinate,
start point y-coordinate,
end point x-coordinate,
end point y-coordinate
)
18drawLine()
starting point
end point
- g.drawLine( 0, 0, 300, 200)
19drawRect()
- draws a rectangle based on its coordinates
object.drawRect(
upper left x-coordinate,
- width and height of rectangle should be non
negative values
upper left y-coordinate,
width of rectangle,
height of rectangle,
)
20drawRect()
width of rectangle,
height of rectangle,
g.drawRect(15, 10, 270, 20)
upper left x-coordinate,
upper left y-coordinate,
21drawString()
draws a string at the specified location
syntax
object.drawString(string, x-coordinate,
y-coordinate)
string to print
- coordinates (or position) at which the string is
drawn
- coordinates are measured from the upper left
corner of applet
22drawString
object.drawString(The sum is sum , 25, 25)
string to print
x-coordinate
y-coordinate
23Additional Graphics