-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnnot.java
More file actions
70 lines (58 loc) · 1.94 KB
/
Annot.java
File metadata and controls
70 lines (58 loc) · 1.94 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// FUB-Annotat/Annot.java
// taha burak sahin pjatk
import java.awt.GridLayout;
import java.awt.Color;
import java.lang.reflect.Field;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class Annot extends JFrame {
@ButProps(panel=1,red=0,message="But1")
JButton b1 = new JButton();
@ButProps(panel=0,red=0,blue=255,message="But2")
JButton b2 = new JButton();
@ButProps(panel=0,green=0,message="But3")
JButton b3 = new JButton();
@ButProps(panel=1,green=0,blue=255,message="But4")
JButton b4 = new JButton();
public static void main(String[] args) {
final Annot a = new Annot();
SwingUtilities.invokeLater( new Runnable() {
public void run() {
a.pack();
a.setVisible(true);
}
});
}
public Annot() {
super("Annotations");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridLayout(2,1,5,5));
JPanel[] panels = {new JPanel(), new JPanel()};
configure(panels);
add(panels[0]);
add(panels[1]);
}
private void configure(JPanel[] panels) {
Class thisClass = getClass();
for (Field f : thisClass.getDeclaredFields()) {
ButProps ann = f.getAnnotation(ButProps.class);
if (ann == null) continue;
System.err.println("\nField : " +
f.getName() +"\nAnnotation: " + ann);
JButton b = null;
try {
b = (JButton)f.get(this);
} catch(IllegalAccessException e) {
e.printStackTrace();
System.exit(1);
}
b.setBackground(new Color(ann.red(),
ann.green(),
ann.blue()));
b.setText(ann.message());
panels[ann.panel()].add(b);
}
}
}