Java Reference
In-Depth Information
final ActionListener generalActionListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
JComponent comp = (JComponent)actionEvent.getSource();
System.out.println (
actionEvent.getActionCommand() + ": " + comp.getBounds());
}
};
final ActionListener sizingActionListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
setupButtons(actionEvent.getActionCommand());
}
};
Runnable runner = new Runnable() {
public void run() {
JFrame frame = new JFrame("Overlay Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel() {
public boolean isOptimizedDrawingEnabled() {
return false;
}
};
LayoutManager overlay = new OverlayLayout(panel);
panel.setLayout(overlay);
Object settings[][] = {
{"Small", new Dimension(25, 25), Color.white},
{"Medium", new Dimension(50, 50), Color.gray},
{"Large", new Dimension(100, 100), Color.black}
};
JButton buttons[] = {smallButton, mediumButton, largeButton};
for (int i=0, n=settings.length; i<n; i++) {
JButton button = buttons[i];
button.addActionListener(generalActionListener);
button.setActionCommand((String)settings[i][0]);
button.setMaximumSize((Dimension)settings[i][1]);
button.setBackground((Color)settings[i][2]);
panel.add(button);
}
Search WWH ::




Custom Search