中显示 YOU PRESSED YES,点击第二个按钮 ,在文本框中显示 you pressed no。
//找到一个以前的,不知道适不适合你
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class SetPerformance extends Applet {
Button button1=new Button("YES");
Button button2=new Button("NO");
TextField t1=new TextField(30);
public SetPerformance(){
button1.addActionListener(new B1());
button2.addActionListener(new B2());
add(button1);
add(button2);
add(t1);
}
class B1 implements ActionListener{
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
t1.setText("YOU PRESSED YES");
}
}
class B2 implements ActionListener{
public void actionPerformed(ActionEvent e){
t1.setText("YOU PRESSED NO");
}
}
public static void main(String []args){
SetPerformance p=new SetPerformance();
Frame f=new Frame();
f.setSize(300, 400);
f.setVisible(true);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}});
f.add(p,BorderLayout.CENTER);
}
}
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class SetPerformance extends Applet {
Button button1=new Button("YES");
Button button2=new Button("NO");
TextField t1=new TextField(30);
public SetPerformance(){
button1.addActionListener(new B1());
button2.addActionListener(new B2());
add(button1);
add(button2);
add(t1);
}
class B1 implements ActionListener{
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
t1.setText("YOU PRESSED YES");
}
}
class B2 implements ActionListener{
public void actionPerformed(ActionEvent e){
t1.setText("YOU PRESSED NO");
}
}
public static void main(String []args){
SetPerformance p=new SetPerformance();
Frame f=new Frame();
f.setSize(300, 400);
f.setVisible(true);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}});
f.add(p,BorderLayout.CENTER);
}
}
温馨提示:答案为网友推荐,仅供参考