-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMyJButton.java
158 lines (140 loc) · 3.82 KB
/
MyJButton.java
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*;
// My own implementation of Graphical controls
class MyJButton extends JButton
{
public MyJButton(ImageIcon icon)
{
super(icon);
setBackground(Color.white);
setContentAreaFilled(false);
setBorderPainted(false);
}
public MyJButton(ImageIcon icon, ImageIcon rollOverIcon)
{
super(icon);
setRolloverIcon(rollOverIcon);
setPressedIcon(icon);
setBackground(Color.white);
setContentAreaFilled(false);
setBorderPainted(false);
}
public MyJButton(String icon)
{
super(new ImageIcon(icon));
setBackground(Color.white);
setContentAreaFilled(false);
setBorderPainted(false);
}
public MyJButton(String icon, String rollOverIcon)
{
super(new ImageIcon(icon));
setRolloverIcon(new ImageIcon(rollOverIcon));
setPressedIcon(new ImageIcon(icon));
setBackground(Color.white);
setContentAreaFilled(false);
setBorderPainted(false);
}
public MyJButton(String caption, Color foreground, Color background)
{
super(caption);
setForeground(foreground);
setBackground(background);
}
}
class MyJLabel extends JLabel
{
public MyJLabel(String caption, Color foreground, Color background)
{
super(caption);
setForeground(foreground);
setBackground(background);
}
public MyJLabel(String caption, Font font, Color foreground, Color background)
{
super(caption);
setForeground(foreground);
setBackground(background);
setFont(font);
}
}
class MyJTextField extends JTextField
{
public MyJTextField(String caption, int size, Color foreground, Color background)
{
super(caption, size);
setForeground(foreground);
setBackground(background);
}
}
class MyJMenu extends JMenu
{
public MyJMenu(String caption, int mnemonicIndex, int mnemonic)
{
super(caption);
setDisplayedMnemonicIndex(mnemonicIndex);
setMnemonic(mnemonic);
}
}
class MyJMenuItem extends JMenuItem
{
public MyJMenuItem(String caption, int mnemonicIndex, int mnemonic)
{
super(caption);
setDisplayedMnemonicIndex(mnemonicIndex);
setMnemonic(mnemonic);
}
}
class MyJRadioButtonMenuItem extends JRadioButtonMenuItem
{
public MyJRadioButtonMenuItem(String caption, int mnemonicIndex, int mnemonic)
{
super(caption);
setDisplayedMnemonicIndex(mnemonicIndex);
setMnemonic(mnemonic);
}
}
// Class to perform utility operations
class UtilityOperations
{
public static JPanel createBorderedPanel(JPanel panel, String title, int hPad, int vPad)
{
int i;
char chars[]= new char[hPad];
for(i=0; i<chars.length; i++) chars[i]= ' ';
String hString= new String(chars);
chars= new char[vPad];
for(i=0; i<chars.length; i++) chars[i]= ' ';
String vString= new String(chars);
JPanel newPanel= new JPanel();
newPanel.setLayout(new BorderLayout());
newPanel.add(panel, BorderLayout.CENTER);
newPanel.add(new JLabel(vString), BorderLayout.NORTH);
newPanel.add(new JLabel(vString), BorderLayout.SOUTH);
newPanel.add(new JLabel(hString), BorderLayout.EAST);
newPanel.add(new JLabel(hString), BorderLayout.WEST);
newPanel.setBorder(new TitledBorder(title));
newPanel.setBackground(panel.getBackground());
newPanel.setForeground(panel.getForeground());
return newPanel;
}
public static JPanel createBorderedPanel(JPanel panel, int hPad, int vPad)
{
int i;
char chars[]= new char[hPad];
for(i=0; i<chars.length; i++) chars[i]= ' ';
String hString= new String(chars);
chars= new char[vPad];
for(i=0; i<chars.length; i++) chars[i]= ' ';
String vString= new String(chars);
JPanel newPanel= new JPanel();
newPanel.setLayout(new BorderLayout());
newPanel.add(panel, BorderLayout.CENTER);
newPanel.add(new JLabel(vString), BorderLayout.NORTH);
newPanel.add(new JLabel(vString), BorderLayout.SOUTH);
newPanel.add(new JLabel(hString), BorderLayout.EAST);
newPanel.add(new JLabel(hString), BorderLayout.WEST);
return newPanel;
}
}