-
Notifications
You must be signed in to change notification settings - Fork 1
/
GraphicsDemo2.java
48 lines (39 loc) · 1.43 KB
/
GraphicsDemo2.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import java.awt.*;
import javax.swing.JFrame;
public class GraphicsDemo2 extends Canvas {
public void paint(Graphics g) {
g.setColor(Color.black);
g.drawRect(50, 20, 100, 200); // draw a rectangle
g.drawOval(160, 20, 100, 200); // draw a filled-in oval
// arcs
g.drawArc(270, 20, 100, 200, 0, 270); // draw an arc that starts at 0 degrees
g.drawArc(50, 250, 150, 150, 90, 180);
g.drawArc(210, 250, 150,150,45,80);
g.fillArc(210,280,150,150,45,90);
g.setColor(Color.yellow);
g.fillArc(150,400,150,150,45,270); // chomp
g.setColor(Color.pink);
g.fillArc(350, 400, 100, 100, 135,-270 );
// custom colors
Color myOrange = new Color(230,92,0); // amount of red, green and blue in the color
// Each component has a value from 0-255
g.setColor(myOrange);
g.fillOval(500, 50, 150, 150);
Color myGrey = new Color(238, 238, 238);
g.setColor(myGrey);
g.fillOval(550,100,50,50);
Color myBlue = new Color(102, 51, 255);
g.setColor(myBlue);
g.fillOval(500,210,150,150);
g.setColor(Color.green);
g.fillOval(500,370,150,150);
}
public static void main(String[] args) {
JFrame win = new JFrame("GraphicsDemo2: Arcs and Colors");
win.setSize(800, 600);
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GraphicsDemo2 canvas = new GraphicsDemo2();
win.add(canvas);
win.setVisible(true);
}
}