forked from ChrisMayfield/ThinkJavaCode2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMickey.java
More file actions
43 lines (34 loc) · 1.08 KB
/
Mickey.java
File metadata and controls
43 lines (34 loc) · 1.08 KB
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
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import javax.swing.JFrame;
public class Mickey extends Canvas {
public static void main(String[] args) {
JFrame frame = new JFrame("Mickey Mouse");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Canvas canvas = new Mickey();
canvas.setSize(400, 400);
canvas.setBackground(Color.white);
frame.add(canvas);
frame.pack();
frame.setVisible(true);
}
public void paint(Graphics g) {
Rectangle bb = new Rectangle(100, 100, 200, 200);
mickey(g, bb);
}
public void boxOval(Graphics g, Rectangle bb) {
g.fillOval(bb.x, bb.y, bb.width, bb.height);
}
public void mickey(Graphics g, Rectangle bb) {
boxOval(g, bb);
int hx = bb.width / 2;
int hy = bb.height / 2;
Rectangle half = new Rectangle(bb.x, bb.y, hx, hy);
half.translate(-hx / 2, -hy / 2);
boxOval(g, half);
half.translate(hx * 2, 0);
boxOval(g, half);
}
}