-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHead.java
More file actions
executable file
·56 lines (47 loc) · 1.26 KB
/
Copy pathHead.java
File metadata and controls
executable file
·56 lines (47 loc) · 1.26 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
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JPanel;
import javax.swing.border.BevelBorder;
public class Head extends JPanel {
private static final long serialVersionUID = -5358188138402685043L;
private boolean mouseInside;
public Head() {
setBackground(Color.WHITE);
setPreferredSize(new Dimension(500, 500));
setBorder(new BevelBorder(BevelBorder.RAISED));
this.addMouseListener(new MouseAdapter() {
@Override
public void mouseExited(MouseEvent e) {
mouseInside = false;
Head.this.repaint();
}
@Override
public void mouseEntered(MouseEvent e) {
mouseInside = true;
Head.this.repaint();
}
});
}
@Override
public void paintComponent(final Graphics g) {
super.paintComponent(g);
g.setColor(Color.PINK);
g.fillOval(100, 100, 200, 220);
if (mouseInside) {
g.setColor(Color.RED);
g.drawOval(150, 135, 30, 5);
g.drawOval(200, 135, 30, 5);
g.drawArc(170, 230, 40, 30, 180, 180);
}
else {
g.setColor(Color.RED);
g.drawOval(160, 139, 5, 30);
g.drawOval(210, 139, 5, 30);
g.drawArc(170, 230, 40, 30, 180, 180);
}
}
}