Abstract Window Toolkit - PowerPoint PPT Presentation

About This Presentation
Title:

Abstract Window Toolkit

Description:

draws a string at the specified location. object.drawString('string', x-coordinate, y-coordinate) ... coordinates (or position) at which the string is drawn ... – PowerPoint PPT presentation

Number of Views:64
Avg rating:3.0/5.0
Slides: 24
Provided by: effien
Learn more at: https://owd.tcnj.edu
Category:

less

Transcript and Presenter's Notes

Title: Abstract Window Toolkit


1
Abstract Window Toolkit
2
Abstract Window Toolkit
  • class library
  • graphics
  • lines
  • rectangles
  • circles
  • GUI
  • text boxes
  • labels
  • command buttons

3
Java Application
  • javac SomeApp.java
  • java SomeApp

compiling
executing
4
Java Application
  • execution starts with main

public static void main(String args )
5
Java Applet
  • javac SomeApplet.java
  • appletviewer SomeApplet.html

compiling
executing
machine code
html source
appletviewer
6
Java Applet
  • execution starts with the browser / appletviewer
  • browser / appletviewer loads the .class file

7
Appletviewer
  • executes applet
  • utility to test applets
  • included with J2SDK

8
Java Applet
keyword
public class Intersection extends Applet
class name
base class
class Intersection inherits from base class Applet
9
Java Applet
java applet has the following methods
public void init()
public void start()
public void paint(Graphics g)
public void stop()
public void destroy()
10
Java Applet
public void init()
  • first method called by the browser or appletviewer
  • initializes the applet

11
Java Applet
public void paint(Graphics g)
  • after init()
  • refreshing the browser

12
HyperText 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
13
Java Applet
the following must exist before executing an
applet
  • className.html
  • className.java
  • className.class

14
Intersection 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)

15
Graphics
  • setColor()
  • drawLine()
  • drawRect()
  • drawString()

16
setColor
sets color
  • g.setColor(Color.black)
  • where g is the object

17
drawLine()
  • draws a line

g.drawLine(
start point x-coordinate,
start point y-coordinate,
end point x-coordinate,
end point y-coordinate
)
18
drawLine()
starting point
end point
  • g.drawLine( 0, 0, 300, 200)
  • method name
  • draws a line

19
drawRect()
  • 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,
)
20
drawRect()
width of rectangle,
height of rectangle,
g.drawRect(15, 10, 270, 20)
upper left x-coordinate,
upper left y-coordinate,
21
drawString()
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

22
drawString
object.drawString(The sum is sum , 25, 25)
string to print
x-coordinate
y-coordinate
23
Additional Graphics
  • See page 163
Write a Comment
User Comments (0)
About PowerShow.com