import java awt public class Graphics Intro public
![import java. awt. *; public class Graphics. Intro { public static void main(String[] args) import java. awt. *; public class Graphics. Intro { public static void main(String[] args)](https://slidetodoc.com/presentation_image_h2/6a00dd6162f3ea51961d9189378970e7/image-1.jpg)
import java. awt. *; public class Graphics. Intro { public static void main(String[] args) { Drawing. Panel panel = new Drawing. Panel(350, 150); Graphics 2 D g = panel. get. Graphics(); g. draw. Line(50, 100, 100); g. draw. Rect(150, 50, 50); g. draw. Oval(250, 50, 50); } }

(x, y) Coordinates are in pixels starting at (0, 0) in the upper left corner. ● x grows rightward ● y grows downward (opposite of math graphing) ●

draw. Line(int x 1, int y 1, int x 2, int y 2) g. draw. Line(50, 100, 100); draw. Rect(int x, int y, int width, int height) g. draw. Rect(150, 50, 50); draw. Oval(int x, int y, int width, int height) g. draw. Oval(250, 50, 50);

g. set. Stroke(new Basic. Stroke(10)); g. draw. Line(50, 100, 100); g. draw. Rect(150, 50, 50); g. draw. Oval(250, 50, 50);

There also methods for filled objects: fill. Rect(int x, int y, int width, int height) g. fill. Rect(150, 50, 50); fill. Oval(int x, int y, int width, int height) g. fill. Oval(250, 50, 50);

Colors are specified by Color class constants named: BLACK, BLUE, CYAN, DARK_GRAY, GREEN, LIGHT_GRAY, MAGENTA, ORANGE, PINK, RED, WHITE, YELLOW � Pass these to the Graphics object's set. Color method. � Example: g. set. Color(Color. BLACK); g. fill. Rect(10, 30, 100, 50); g. set. Color(Color. RED); g. fill. Oval(60, 40, 70); The background color can be set by calling set. Background on the Drawing. Panel: � Example: panel. set. Background(Color. YELLOW);

Activity – draw this figure: Graphics methods: draw. Line(x 1, y 1, x 2, y 2) draw. Rect(x, y, width, height) draw. Oval(x, y, width, height) fill. Rect(x, y, width, height) fill. Oval(x, y, width, height) set. Color(Color) public static void main(String[] args) { Drawing. Panel panel = new Drawing. Panel(200, 200); Graphics g = panel. get. Graphics(); . . .

You can construct your own Color objects. ● Colors are specified by three integers from 0 to 255 representing the amount of red, green, and blue. ● Computers use red-green-blue or "RGB" as primary colors. Example: Color brown = new Color(192, 128, 64); panel. set. Background(brown); or just: panel. set. Background(new Color(192, 128, 64));

Drawing text: draw. String(string, x, y); // (x, y) is left side baseline Example: g. draw. String(“Drawing is fun!”, 50);

You can select fonts by name, style, and size. Font names: "San. Serif" "Monospaced" like Arial like Times New Roman like Courier New Font styles: Font. BOLD Font. ITALIC Font. BOLD + Font. ITALIC Font. PLAIN Font size: Default is 12 point (72 points / inch) Example: g. set. Font( new Font("Serif", Font. BOLD, 72) );

g. set. Font(new Font("Sans. Serif", Font. PLAIN, 25)); g. draw. String("Sans. Serif - PLAIN", 50); g. set. Font(new Font("Serif", Font. BOLD, 25)); g. draw. String("Serif - BOLD", 50, 100); g. set. Font(new Font("Monospaced", Font. ITALIC, 25)); g. draw. String("Monospaced - ITALIC", 50, 150);

Activity – draw one of these logos
- Slides: 12