GUI Test
[Up]
Source Code
import java.awt.Button;
import java.awt.Choice;
import java.awt.Checkbox;
import java.awt.CheckboxGroup;
import java.awt.Label;
import java.awt.FlowLayout;
import java.awt.BorderLayout;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import java.applet.Applet;
public class GUItest extends Applet implements ActionListener, ItemListener {
Button b1, b2;
Label lb;
Choice ch;
CheckboxGroup cg;
Checkbox cb1, cb2, cb3, cb4;
TextField tf;
public void init() {
Panel p;
setLayout(new BorderLayout());
p = new Panel();
ch = new Choice();
ch.addItem("0");
ch.addItem("10");
ch.addItem("20");
ch.addItem("30");
ch.addItemListener(this);
p.add(ch);
cg = new CheckboxGroup();
cb1 = new Checkbox("Learning", cg, true);
cb1.addItemListener(this);
cb2 = new Checkbox("Adaptive", cg, false);
cb2.addItemListener(this);
cb3 = new Checkbox("H infty", cg, false);
cb3.addItemListener(this);
cb4 = new Checkbox("Sliding Mode", cg, false);
cb4.addItemListener(this);
p.add(cb1); p.add(cb2); p.add(cb3); p.add(cb4);
add("North", p);
lb = new Label("Label", Label.CENTER);
add("Center", lb);
p = new Panel();
b1 = new Button("Start");
b1.setActionCommand("Start");
b1.addActionListener(this);
b2 = new Button("Stop ");
b2.setActionCommand("Stop");
b2.addActionListener(this);
p.add(b1); p.add(b2);
tf = new TextField(20);
tf.addActionListener(this);
p.add(tf);
add("South", p);
}
public void itemStateChanged(ItemEvent evt) {
if (evt.getSource() == ch) {
lb.setText("Choice #" + ch.getSelectedIndex() + " Text ["
+ ch.getSelectedItem() + "]");
}
else {
lb.setText("CheckBox [" + evt.getItem().toString() + "]");
}
}
public void actionPerformed(ActionEvent evt) {
if (evt.getSource() == tf) {
lb.setText("Text [" + tf.getText() + "]");
tf.selectAll();
}
else {
String command = evt.getActionCommand();
lb.setText("Button [" + command + "]");
}
}
}
naniwa@rbt.his.fukui-u.ac.jp