001: /*
002: * Copyright (C) 2004 TiongHiang Lee
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: * Email: thlee@onemindsoft.org
019: */
020:
021: package org.onemind.swingweb.widgetdemo;
022:
023: import java.awt.*;
024: import java.awt.event.ActionEvent;
025: import java.awt.event.ActionListener;
026: import java.io.InputStream;
027: import javax.swing.*;
028: import javax.swing.event.ChangeEvent;
029: import javax.swing.event.ChangeListener;
030: import org.onemind.swingweb.component.layout.TableLayout;
031:
032: public class LabelButtonTextDemo extends AbstractDemo implements
033: ActionListener, ChangeListener {
034:
035: public LabelButtonTextDemo(DemoConsole console) {
036: super ("Label, Button and Text", console);
037: setLayout(new FlowLayout());
038: add(getDemoArea());
039: }
040:
041: public Container getDemoArea() {
042: JPanel pnl = new JPanel();
043: TableLayout layout = new TableLayout(pnl);
044: pnl.setLayout(layout);
045: layout.getConstraint().fill = GridBagConstraints.BOTH;
046: layout.getConstraint().insets = new Insets(5, 5, 5, 5);
047: Icon icon = new ImageIcon(getClass().getResource(
048: "/org/onemind/swingweb/widgetdemo/icecream.jpg"));
049:
050: /** labels **/
051: //just a label
052: JLabel lbl = new JLabel("This is a yellow JLabel");
053: lbl.setForeground(Color.YELLOW);
054: layout.addNextRow(lbl);
055:
056: //label with colors
057: lbl = new JLabel(
058: "<html>This is a <font color=\"blue\"><i>html</i></font> JLabel</html>");
059: layout.addNextRow(lbl);
060:
061: //label with icon
062: lbl = new JLabel("JLabel with icon");
063: lbl.setIcon(icon);
064: layout.addNextRow(lbl);
065:
066: //disabled label
067: lbl = new JLabel("Disabled JLabel");
068: layout.addNextRow(lbl);
069:
070: /** buttons **/
071: //button
072: JButton btn = new JButton("Button1");
073: btn.setBackground(Color.YELLOW);
074: layout.addNextRow(btn);
075: layout.addNextCell(new JLabel(
076: "Just a JButton with yellow background"));
077:
078: //button with listener
079: btn = new JButton("Button2");
080: btn.addActionListener(this );
081: layout.addNextRow(btn);
082: layout.addNextCell(new JLabel(
083: "JButton with listener. Push will submit"));
084:
085: //button with no border
086: btn = new JButton("Button3");
087: btn.setBorder(null);
088: layout.addNextRow(btn);
089: layout.addNextCell(new JLabel("JButton with no border"));
090:
091: //button with icon
092: btn = new JButton("Button4");
093: btn.setIcon(icon);
094: layout.addNextRow(btn);
095: layout.addNextCell(new JLabel("JButton with icon"));
096:
097: /** checkboxes **/
098: //button
099: JCheckBox checkbox = new JCheckBox("Checkbox1");
100: checkbox.setBackground(Color.YELLOW);
101: layout.addNextRow(checkbox);
102: layout.addNextCell(new JLabel(
103: "Just a JCheckbox with yellow background"));
104:
105: //button with listener
106: checkbox = new JCheckBox("Checkbox2");
107: checkbox.addChangeListener(this );
108: layout.addNextRow(checkbox);
109: layout.addNextCell(new JLabel(
110: "JCheckBox with change listener. Push will submit"));
111:
112: //button in a group
113: JPanel subPanel = new JPanel();
114: subPanel.setLayout(new GridLayout(1, 2));
115: ButtonGroup group = new ButtonGroup();
116: checkbox = new JCheckBox("Checkbox3");
117: group.add(checkbox);
118: subPanel.add(checkbox);
119: checkbox = new JCheckBox("Checkbox4");
120: group.add(checkbox);
121: subPanel.add(checkbox);
122: layout.addNextRow(subPanel);
123: layout.addNextCell(new JLabel(
124: "JCheckBox in button group. Push always submit"));
125:
126: /** radio buttons **/
127: // button in a group
128: subPanel = new JPanel();
129: subPanel.setLayout(new GridLayout(1, 2));
130: group = new ButtonGroup();
131: JRadioButton rbtn = new JRadioButton("RadioButton1");
132: group.add(rbtn);
133: subPanel.add(rbtn);
134: rbtn = new JRadioButton("RadioButton2");
135: group.add(rbtn);
136: subPanel.add(rbtn);
137: layout.addNextRow(subPanel);
138: layout.addNextCell(new JLabel("RadioButtons in button group"));
139:
140: //button in a group with listener
141: subPanel = new JPanel();
142: subPanel.setLayout(new GridLayout(1, 2));
143: group = new ButtonGroup();
144: rbtn = new JRadioButton("RadioButton1");
145: group.add(rbtn);
146: rbtn.addChangeListener(this );
147: subPanel.add(rbtn);
148: rbtn = new JRadioButton("RadioButton2");
149: group.add(rbtn);
150: rbtn.addActionListener(this );
151: subPanel.add(rbtn);
152: layout.addNextRow(subPanel);
153: layout
154: .addNextCell(new JLabel(
155: "RadioButtons with change/action listener in button group. Push will submit"));
156:
157: /** text demo **/
158: //Text field
159: JTextField fld = new JTextField();
160: fld.setColumns(10);
161: fld.setText("Test");
162: layout.addNextRow(fld);
163: layout.addNextCell(new JLabel("Just a text field"));
164:
165: //Text field with TextListner
166: fld = new JTextField();
167: fld.setColumns(10);
168: fld.setText("Test");
169: layout.addNextRow(fld);
170: layout.addNextCell(new JLabel("Texd field with text listener"));
171:
172: //Password field
173: fld = new JPasswordField();
174: fld.setColumns(10);
175: layout.addNextRow(fld);
176: layout.addNextCell(new JLabel("A password field"));
177:
178: //Text area
179: JTextArea tfld = new JTextArea();
180: tfld.setColumns(10);
181: tfld.setRows(4);
182: layout.addNextRow(tfld);
183: layout.addNextCell(new JLabel("A text area"));
184: return pnl;
185: }
186:
187: public void actionPerformed(ActionEvent e) {
188: getConsole().log(e.toString());
189: }
190:
191: public void stateChanged(ChangeEvent e) {
192: getConsole().log(e.toString());
193: }
194: }
|