-
Notifications
You must be signed in to change notification settings - Fork 0
/
RobotFace.java
52 lines (38 loc) · 1.14 KB
/
RobotFace.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
49
50
51
52
import javax.swing.*;
import java.awt.*;
public class RobotFace extends JFrame {
public RobotFace() {
setTitle("Robot Face");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400, 400);
setResizable(true);
setLocationRelativeTo(null);
FacePanel facePanel = new FacePanel();
add(facePanel);
setVisible(true);
}
public static void main(String[] args) {
RobotFace f = new RobotFace();
}
}
class FacePanel extends JPanel {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
// Set background color
setBackground(Color.WHITE);
// Set face color
g.setColor(Color.LIGHT_GRAY);
// Draw the face
g.fillOval(100, 100, 200, 200);
// Set eye color
g.setColor(Color.BLUE);
// Draw the eyes
g.fillOval(150, 160, 40, 40);
g.fillOval(210, 160, 40, 40);
// Set mouth color
g.setColor(Color.RED);
// Draw the mouth
g.fillArc(150, 220, 100, 60, 0, -180);
}
}