编写一个GUI 程序 界面有2个按钮和一个文本框 ,按钮文本分别为YES 和 NO ,点击第一个按钮,在文本框
中显示YOUPRESSEDYES,点击第二个按钮,在文本框中显示youpressedno。...
中显示 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);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询