Commit | Line | Data |
---|---|---|
255d3354 JB |
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 LeftPersonPanel extends JPanel { | |
8 | private JLabel leftLabel = new JLabel(); | |
9 | private Image personImage; | |
10 | ||
11 | LeftPersonPanel() { | |
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 | System.out.println(e.getStackTrace()); | |
18 | } | |
19 | } | |
20 | ||
21 | public Image getPersonImage() { | |
22 | return personImage; | |
23 | } | |
24 | ||
25 | public void paintComponent(Graphics g) { | |
26 | super.paintComponent(g); | |
27 | ||
28 | // Draw | |
29 | g.setColor(Color.black); | |
30 | Graphics2D g2d = (Graphics2D) g; | |
31 | int imageWidth = 120; | |
32 | int imageHeight = 180; | |
33 | g2d.drawImage(this.personImage.getScaledInstance(imageWidth / 2, imageHeight / 2, Image.SCALE_SMOOTH), imageWidth / 4, imageHeight / 4, this); | |
34 | } | |
35 | } |