日期:2014-05-20 浏览次数:20773 次
import java.awt.*;
import java.awt.event.*;
public class TestListButton {
public static void main(String[] args) {
// TODO Auto-generated method stub
new MyListButton ("下拉表与按钮");
}
}
class MyListButton extends Frame implements ItemListener {
private static final long serialVersionUID = 1L;
String sl;
List l;
Button b;
MyListButton (String s) {
super (s);
this.setLayout(new FlowLayout());
this.setBounds(500, 500, 600, 300);
l = new List(3,false);
l.add("10");
l.add("14");
l.add("18");
b = new Button("10");
l.addItemListener(this);
add(l);
add(b);
this.setVisible(true);
}
public void itemStateChanged(ItemEvent e) {
// TODO Auto-generated method stub
sl = e.paramString();
b.setLabel(sl);
}
}
import java.awt.*;
import java.awt.event.*;
public class TestListButton {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new MyListButton("下拉表与按钮").setVisible(true);
}
});
}
}
class MyListButton extends Frame implements ItemListener {
private static final long serialVersionUID = 1L;
String sl;
List l;
Button b;
MyListButton(String s) {
super(s);
this.setLayout(new FlowLayout());
this.setBounds(500, 500, 600, 300);
l = new List(3, false);
l.add("10");
l.add("14");
l.add("18");
b = new Button("10");
l.addItemListener(this);
add(l);
add(b);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
dispose();
}
});
}
@Override
public void itemStateChanged(ItemEvent e) {
b.setLabel(l.getSelectedItem());