forked from alexlorenlee/JavaTutorialCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmickey.java
More file actions
55 lines (43 loc) · 1.36 KB
/
Copy pathmickey.java
File metadata and controls
55 lines (43 loc) · 1.36 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
44
45
46
47
48
49
50
51
52
53
54
55
/********************************************************
* Example taken from https://books.trinket.io/thinkjava2/appendix-c.html
********************************************************/
import javax.swing.JFrame;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Rectangle;
public class mickey extends JFrame {
public static void main(String args[]) {
new mickey();
}
public mickey() {
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public void paint(Graphics g) {
g.setColor(Color.WHITE);
g.fillRect(0, 0, 400, 300);
Font f1 = new Font("Rockwell", Font.PLAIN, 20);
g.setFont(f1);
g.setColor(Color.blue);
g.drawString("Sushaant K", 100, 200);
// Add Student ID nationality hobbies etc., here
g.setColor(Color.blue);
paintMickey(g, new Rectangle(50, 60, 100, 100));
}
public void boxOval(Graphics g, Rectangle bb) {
g.fillOval(bb.x, bb.y, bb.width, bb.height);
System.out.println("x= " + bb.x + "; y= " + bb.y + " width= " + bb.width + " height= " + bb.height);
}
public void paintMickey(Graphics g, Rectangle bb) {
boxOval(g, bb);
int dx = bb.width / 2;
int dy = bb.height / 2;
Rectangle half = new Rectangle(bb.x, bb.y, dx, dy);
half.translate(-dx / 2, -dy / 2);
boxOval(g, half);
half.translate(dx * 2, 0);
boxOval(g, half);
}
}