e8cb6f71d5a8dc5a8896c9f10887beb57dccacb4
[Persons_Comparator.git] / src / PersonLeftPanel.java
1 import javax.imageio.ImageIO;
2 import javax.swing.*;
3 import java.awt.*;
4 import java.io.File;
5 import java.io.IOException;
6
7 public class PersonLeftPanel extends JPanel {
8 private JLabel leftLabel = new JLabel();
9 private Image personImage;
10
11 PersonLeftPanel() {
12 leftLabel.setText("Current person");
13 add(leftLabel);
14 try {
15 this.personImage = ImageIO.read(new File("data/personImage.png"));
16 } catch (IOException e) {
17 e.printStackTrace();
18 }
19 }
20
21 private void draw(Graphics g) {
22 // Draw
23 Graphics2D g2d = (Graphics2D) g;
24 int imageWidth = 120;
25 int imageHeight = 180;
26 g2d.drawImage(this.personImage.getScaledInstance(imageWidth / 2, imageHeight / 2, Image.SCALE_SMOOTH), imageWidth / 4, imageHeight / 4, this);
27 }
28
29 @Override
30 public void paintComponent(Graphics g) {
31 super.paintComponent(g);
32 draw(g);
33 }
34
35 //FIXME: redraw on resizing
36 /*@Override
37 public void paint(Graphics g) {
38 super.paint(g);
39 draw(g);
40 }*/
41
42 public void drawEyes(Color color) {
43 Graphics g = this.getGraphics();
44 g.setColor(color);
45 g.fillOval(50, 50, 6, 3);
46 g.fillOval(62, 50, 6, 3);
47 }
48
49 public void drawWeight(int weight) {
50 Graphics g = this.getGraphics();
51 g.setColor(Color.black);
52 g.fillOval(44, 76, 30, (weight * 20) / 600);
53 }
54 }