-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInfoPanel.java
More file actions
55 lines (46 loc) · 1.15 KB
/
InfoPanel.java
File metadata and controls
55 lines (46 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import javax.swing.*;
import java.awt.*;
import java.lang.reflect.*;
/** @author Gergely Kota
InfoPanel displays a description for a class
*/
public class InfoPanel extends JLabel
{
private Color text;
private String description;
private int height;
private final String EMPTY = "No description given";
public InfoPanel()
{
description = "No entry selected";
}
public void setDescription(Class c)
{
try
{
Method m = c.getMethod("description", new Class[]{});
Method[] ms = c.getDeclaredMethods();
boolean local = false;
for(int i = 0; i < ms.length; i++)
if(ms[i].equals(m))
local = true;
if(local)
description = (String) m.invoke(null, (Object[])null);
else
description = EMPTY;
}
catch(Exception e) {description = EMPTY;}
setText(description);
}
/* ----------------------------------------------------------- */
/* ----------------------------------------------------------- */
/* ----------------------------------------------------------- */
public static void main(String[] args)
{
JFrame jf = new JFrame();
InfoPanel ip = new InfoPanel();
jf.getContentPane().add(ip);
jf.pack();
jf.show();
}
}