GUI Test using Swing
[Up]
Launch the applet via Java Web Start.
Source Code
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SGUItest extends JApplet implements ActionListener {
private JButton b1, b2;
private JLabel lb;
private JRadioButton cb1, cb2, cb3, cb4;
private ButtonGroup bg = new ButtonGroup();
private JTextField tf;
private JComboBox cb;
public void init() {
JPanel p;
Container cnt = getContentPane();
String[] str = {"0", "10", "20", "30"};
ActionListener al = this;
p = new JPanel();
cb = new JComboBox(str);
p.add(cb);
cb.addActionListener(al);
cb1 = new JRadioButton("Learning", true);
cb1.addActionListener(al);
cb2 = new JRadioButton("Adaptive", false);
cb2.addActionListener(al);
cb3 = new JRadioButton("H infty", false);
cb3.addActionListener(al);
cb4 = new JRadioButton("Sliding Mode", false);
cb4.addActionListener(al);
bg.add(cb1); bg.add(cb2); bg.add(cb3); bg.add(cb4);
p.add(cb1); p.add(cb2); p.add(cb3); p.add(cb4);
cnt.add(p, BorderLayout.NORTH);
lb = new JLabel("Label");
lb.setHorizontalAlignment(JLabel.CENTER);
cnt.add(lb, BorderLayout.CENTER);
p = new JPanel();
b1 = new JButton("Start");
b1.setActionCommand("Start");
b1.addActionListener(al);
b2 = new JButton("Stop ");
b2.setActionCommand("Stop");
b2.addActionListener(al);
p.add(b1); p.add(b2);
tf = new JTextField(20);
tf.addActionListener(al);
p.add(tf);
cnt.add(p, BorderLayout.SOUTH);
}
public void actionPerformed(ActionEvent evt) {
if (evt.getSource() == cb) {
lb.setText("ComboBox [" + cb.getSelectedItem() + "]");
}
else if (evt.getSource() == tf) {
lb.setText("Text [" + tf.getText() + "]");
tf.selectAll();
}
else if (evt.getSource() instanceof JButton) {
String command = evt.getActionCommand();
lb.setText("Button [" + command + "]");
}
else {
String command = evt.getActionCommand();
lb.setText("CheckBox [" + command + "]");
}
}
}
naniwa@rbt.his.u-fukui.ac.jp