Commit | Line | Data |
---|---|---|
d252f672 JB |
1 | import javax.imageio.ImageIO; |
2 | import javax.swing.*; | |
3 | import java.awt.*; | |
4 | import java.awt.geom.Ellipse2D; | |
5 | import java.awt.geom.Point2D; | |
6 | import java.io.File; | |
7 | import java.io.IOException; | |
8 | ||
9 | public class PersonPanel extends JPanel { | |
10 | private boolean debug = true; | |
11 | private String titleText = new String(); | |
12 | private JLabel personLabel = new JLabel(); | |
13 | private String contentText = new String(); | |
14 | private Image personImage; | |
15 | ||
16 | public PersonPanel(String title) { | |
17 | setTitleText(title); | |
18 | personLabel.setText(this.getTitleText()); | |
19 | add(personLabel); | |
20 | try { | |
21 | this.personImage = ImageIO.read(new File("data/personImage.png")); | |
22 | } catch (IOException e) { | |
23 | System.out.println(e.getStackTrace()); | |
24 | } | |
25 | } | |
26 | ||
27 | public void setTitleText(String titleText) { | |
28 | this.titleText = titleText; | |
29 | } | |
30 | ||
31 | public String getTitleText() { | |
32 | return titleText; | |
33 | } | |
34 | ||
35 | public void setContentText(String contentText) { | |
36 | this.contentText = contentText; | |
37 | } | |
38 | ||
39 | public String getContentText() { | |
40 | return contentText; | |
41 | } | |
42 | ||
43 | public void paintComponent(Graphics g) { | |
44 | super.paintComponent(g); | |
45 | ||
46 | // Draw | |
47 | g.setColor(Color.black); | |
48 | if (debug) | |
49 | // Below the JLabel | |
50 | g.drawString(this.getContentText(), 5, 35); | |
51 | Graphics2D g2d = (Graphics2D) g; | |
52 | g2d.drawImage(this.personImage.getScaledInstance(getWidth() / 2, getHeight() / 2, Image.SCALE_SMOOTH), getWidth() / 4, getHeight() / 4, this); | |
53 | } | |
54 | ||
55 | private static Ellipse2D getCircleByCenter(Point2D center, double radius) { | |
56 | Ellipse2D.Double myCircle = new Ellipse2D.Double(center.getX() - radius, center.getY() - radius, 2 * radius, 2 * radius); | |
57 | return myCircle; | |
58 | } | |
59 | } |