Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 11

Java APPLET

Java’s Coordinate System


• To begin drawing in Java, we must first
understand Java’s coordinate system which is
a scheme for identifying every point on the
screen. By default, the upper-left corner of a
GUI component (e.g. a window) has a
coordinates (0,0). A coordinate pair is
composed of an x-coordinate(the horizontal
coordinate) and a y-coordinate (the vertical
coordiante)
Java’s Coordinate System

(0,0) X axis

(x,y)

Y axis
1= 10

(1,3) (9,3)

Java Code:
g.setColor(Color.red);
g.drawLine(10,30,90,30);
1= 10

(1,4)

Width = 4 Java Code:


g.setColor(Color.yellow);
Height = 3
g.drawRect(10,40,40,30);
Color Constant

• RED • YELLOW
• GREEN • BLACK
• BLUE • WHITE
• ORANGE • GRAY
• PINK • LIGHT_GRAY
• CYAN • DARK_GRAY
• MAGENTA
1= 10

(1,4) (6,4)

Width = 4 Width = 4

Height = 3 Height = 3

Java Code:
Java Code:
g.setColor(Color.yellow);
g.setColor(Color.black);
g.drawRect(10,40,40,30);
g.fillRect(60,40,40,30);
ARC WIDTH AND ARC HEIGHT FOR
ROUNDED RECTANGLE

(1,2)

Arc Height = 2

Arc width = 2
Height = 5

Width = 6
Java Code:
g.setColor(Color.blue);
g.fillRoundRect(10,20,60,50,20,20);
OVAL BOUNDED BY A RECTANGLE

(1,2)

Height = 5

Java Code:

Width = 3 g.setColor(Color.red);
g.fillOval(10,20,30,50);
POSITIVE AND NEGATIVE
ARC ANGLES
900

(3,2) POSITIVE

1800 00

Height = 4

NEGATIVE
Width = 4
Java Code:
g.setColor(Color.PINK);
g.fillArc(30,20,40,40,-0,-270); 2700
POLYGONS

(2,4)

Java Code:
(5,5.5) g.setColor(Color.YELLOW);
Polygon p = new Polygon();
p.addPoint(20,40);
(2,7) p.addPoint(50,55);
p.addPoint(20,70);
g.drawPolygon(p);

You might also like