| 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 | System.out.println(e.getStackTrace()); |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | public void paintComponent(Graphics g) { |
| 22 | super.paintComponent(g); |
| 23 | |
| 24 | // Draw |
| 25 | Graphics2D g2d = (Graphics2D) g; |
| 26 | int imageWidth = 120; |
| 27 | int imageHeight = 180; |
| 28 | g2d.drawImage(this.personImage.getScaledInstance(imageWidth / 2, imageHeight / 2, Image.SCALE_SMOOTH), imageWidth / 4, imageHeight / 4, this); |
| 29 | } |
| 30 | |
| 31 | public void drawEyes(Color color) { |
| 32 | Graphics g = this.getGraphics(); |
| 33 | g.setColor(color); |
| 34 | g.fillOval(50, 50, 6, 3); |
| 35 | g.fillOval(62, 50, 6, 3); |
| 36 | } |
| 37 | } |