主题:[讨论]谁帮我看下这个程序,appletviewer中运行时点击按纽都没反映?
Java_2.java 文件
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Java_2 extends Applet implements ActionListener
{
Button b1;
Button b2;
TextField tf1;
TextField tf2;
Label l;
String s;
public Java_2(){
Label l=new Label("请输入你的名字:");
TextField tf1=new TextField(10);
TextField tf2=new TextField(30);
Button btn1=new Button("测试");
Button btn2=new Button("关闭");
add(l);
add(tf1);
add(tf2);
add(btn1);
add(btn2);
btn1.addActionListener(this);
btn2.addActionListener(this);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
s=tf1.getText();
if(e.getActionCommand()=="测试"&&s=="某人")
tf2.setText("100分.");
if(e.getActionCommand()=="关闭")
System.exit(0);
}
}
html 文件
<html>
<applet code="Java_2.class" width=400 height=200>
</applet>
</html>
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Java_2 extends Applet implements ActionListener
{
Button b1;
Button b2;
TextField tf1;
TextField tf2;
Label l;
String s;
public Java_2(){
Label l=new Label("请输入你的名字:");
TextField tf1=new TextField(10);
TextField tf2=new TextField(30);
Button btn1=new Button("测试");
Button btn2=new Button("关闭");
add(l);
add(tf1);
add(tf2);
add(btn1);
add(btn2);
btn1.addActionListener(this);
btn2.addActionListener(this);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
s=tf1.getText();
if(e.getActionCommand()=="测试"&&s=="某人")
tf2.setText("100分.");
if(e.getActionCommand()=="关闭")
System.exit(0);
}
}
html 文件
<html>
<applet code="Java_2.class" width=400 height=200>
</applet>
</html>