Split the person panel into two sub panels : one for the current person, one for...
[Persons_Comparator.git] / src / RightPersonPanel.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 RightPersonPanel extends JPanel {
8 private JLabel rightLabel = new JLabel();
9 private String contentText = new String();
10 private Image personImage;
11
12 RightPersonPanel() {
13 rightLabel.setText("Closest person found");
14 add(rightLabel);
15 try {
16 this.personImage = ImageIO.read(new File("data/personImage.png"));
17 } catch (IOException e) {
18 System.out.println(e.getStackTrace());
19 }
20 }
21
22 public void setContentText(String contentText) {
23 this.contentText = contentText;
24 }
25
26 public String getContentText() {
27 return contentText;
28 }
29
30 public Image getPersonImage() {
31 return personImage;
32 }
33
34 public void paintComponent(Graphics g) {
35 super.paintComponent(g);
36
37 // Draw
38 g.setColor(Color.black);
39 g.drawString(getContentText(), 5, 35);
40 Graphics2D g2d = (Graphics2D) g;
41 int imageWidth = 120;
42 int imageHeight = 180;
43 g2d.drawImage(this.personImage.getScaledInstance(imageWidth / 2, imageHeight / 2, Image.SCALE_SMOOTH), imageWidth / 4, imageHeight / 4, this);
44 }
45 }