01: //WebOnSwing - Web Application Framework
02: //Copyright (C) 2003 Fernando Damian Petrola
03: //
04: //This library is free software; you can redistribute it and/or
05: //modify it under the terms of the GNU Lesser General Public
06: //License as published by the Free Software Foundation; either
07: //version 2.1 of the License, or (at your option) any later version.
08: //
09: //This library is distributed in the hope that it will be useful,
10: //but WITHOUT ANY WARRANTY; without even the implied warranty of
11: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: //Lesser General Public License for more details.
13: //
14: //You should have received a copy of the GNU Lesser General Public
15: //License along with this library; if not, write to the Free Software
16: //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17:
18: package examples;
19:
20: import java.awt.event.*;
21:
22: import javax.swing.*;
23:
24: public class ButtonDemoFrame extends JFrame {
25:
26: public ButtonDemoFrame() {
27: super ("ButtonDemo");
28:
29: addWindowListener(new WindowAdapter() {
30: public void windowClosing(WindowEvent e) {
31: System.exit(0);
32: }
33: });
34:
35: getContentPane().add(new ButtonDemo());
36: }
37:
38: public static class ButtonDemo extends JPanel implements
39: ActionListener {
40: protected static JButton b1, b2, b3;
41: {
42: ImageIcon leftButtonIcon = new ImageIcon("images/right.gif");
43: ImageIcon middleButtonIcon = new ImageIcon(
44: "images/middle.gif");
45: ImageIcon rightButtonIcon = new ImageIcon("images/left.gif");
46:
47: b1 = new JButton("Disable middle button", leftButtonIcon);
48: b1.setVerticalTextPosition(SwingConstants.CENTER);
49: b1.setHorizontalTextPosition(SwingConstants.LEFT);
50: b1.setMnemonic(KeyEvent.VK_D);
51: b1.setActionCommand("disable");
52:
53: b2 = new JButton("Middle button", middleButtonIcon);
54: b2.setVerticalTextPosition(SwingConstants.BOTTOM);
55: b2.setHorizontalTextPosition(SwingConstants.CENTER);
56: b2.setMnemonic(KeyEvent.VK_M);
57:
58: b3 = new JButton("Enable middle button", rightButtonIcon);
59: //Use the default text position of CENTER, RIGHT.
60: b3.setMnemonic(KeyEvent.VK_E);
61: b3.setActionCommand("enable");
62: b3.setEnabled(false);
63:
64: add(b1);
65: add(b2);
66: add(b3);
67: }
68:
69: public ButtonDemo() {
70: b1.addActionListener(this );
71: b3.addActionListener(this );
72: }
73:
74: public void actionPerformed(ActionEvent e) {
75: if (e.getActionCommand().equals("disable")) {
76: b2.setEnabled(false);
77: b1.setEnabled(false);
78: b3.setEnabled(true);
79: } else {
80: b2.setEnabled(true);
81: b1.setEnabled(true);
82: b3.setEnabled(false);
83: }
84: }
85: }
86: }
|