import java.awt.*;
Coordinate System
· A scheme for identifying every point on the screen.
· A coordinate pair is composed of x & y coordinate.
· The coordinates are used to indicate where graphics should be displayed on a screen.
Pixels
· Coordinate units and display monitor’s smallest unit of resolution.
Class Graphics
· An abstract class & contributes to Java’s portability.
Class JComponents
· It contains a paintComponent method that can be used to draw graphics.
public void paintComponent(Graphics g)
JPanel
· Many capabilities of class JPanel are inherited from class JComponents.
JFrame
· A window that decorates such as border, a title, and button components.
Drawing Lines, Rectangles and Ovals
Drawing Lines
· Draw a line between the point (x1, y1) and the point (x2, y2).
Syntax: g.drawLine(x1, y1, x2, y2);
Drawing Rectangles
· Draw a rectangle of the specified width and height.
Syntax: g.drawRect(x, y, width, height);
Drawing Ovals
· Draw an oval in the current color w/ the specified width and height.
Syntax: g.drawOval(x, y, width, height);
Filling Rectangle and Oval
Filling Rectangle
· Draw a filled rectangle w/ the specified width and height in the current background color.
Syntax: g.fillRect(x, y, width, height);
Filling Oval
· Draw a filled oval w/ the specified width and height in the current background color.
Syntax: g.fillOval(x, y, width, height);
Drawing String
· Syntax: g.drawString(string, x, y);
Color Control
· Syntax: g.setColor(Color.COLOR_NAME);
g.setColor(new Color(r,g,b));
Font Control
· Syntax: g.setFont(new Font(font,style,size));
Drawing and Filling Round Rectangle
· Syntax: g.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
g.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
Drawing and Filling Polygon
· Syntax: int x[] = { };
int y[] = { };
g.drawPolygon(xPoints,yPoints,points);
g.fillPolygon(xPoints,yPoints,points);
Drawing Arcs
· Syntax: g.drawArc(x, y, width, height, startAngle, arcAngle);
· (+) angle – counter clockwise
· (-) angle - clockwise
Coordinate System
· A scheme for identifying every point on the screen.
· A coordinate pair is composed of x & y coordinate.
· The coordinates are used to indicate where graphics should be displayed on a screen.
Pixels
· Coordinate units and display monitor’s smallest unit of resolution.
Class Graphics
· An abstract class & contributes to Java’s portability.
Class JComponents
· It contains a paintComponent method that can be used to draw graphics.
public void paintComponent(Graphics g)
JPanel
· Many capabilities of class JPanel are inherited from class JComponents.
JFrame
· A window that decorates such as border, a title, and button components.
Drawing Lines, Rectangles and Ovals
Drawing Lines
· Draw a line between the point (x1, y1) and the point (x2, y2).
Syntax: g.drawLine(x1, y1, x2, y2);
Drawing Rectangles
· Draw a rectangle of the specified width and height.
Syntax: g.drawRect(x, y, width, height);
Drawing Ovals
· Draw an oval in the current color w/ the specified width and height.
Syntax: g.drawOval(x, y, width, height);
Filling Rectangle and Oval
Filling Rectangle
· Draw a filled rectangle w/ the specified width and height in the current background color.
Syntax: g.fillRect(x, y, width, height);
Filling Oval
· Draw a filled oval w/ the specified width and height in the current background color.
Syntax: g.fillOval(x, y, width, height);
Drawing String
· Syntax: g.drawString(string, x, y);
Color Control
· Syntax: g.setColor(Color.COLOR_NAME);
g.setColor(new Color(r,g,b));
Font Control
· Syntax: g.setFont(new Font(font,style,size));
Drawing and Filling Round Rectangle
· Syntax: g.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
g.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
Drawing and Filling Polygon
· Syntax: int x[] = { };
int y[] = { };
g.drawPolygon(xPoints,yPoints,points);
g.fillPolygon(xPoints,yPoints,points);
Drawing Arcs
· Syntax: g.drawArc(x, y, width, height, startAngle, arcAngle);
· (+) angle – counter clockwise
· (-) angle - clockwise