JAVA applet问题

来源:百度知道 编辑:UC知道 时间:2024/05/17 22:36:37
一个小写变到大写的程序 但有错误 实在是找不出 高手指点!谢谢
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Test extends Applet implements ActionListener
{
Label l1=new Label("请输入单词:");
TextField t1=new TextField(4);
Button b1=new Button("大写");
Label l2=new Label("此处显示大写单词");
}

public void init()
{
add(l1);
add(t1);
add(b1);
add(l2);
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String s=t1.getText();
String upperCase=s.toUpperCase();
l2.setText(upperCase);
}
});
}

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Test extends Applet implements ActionListener
{
Label l1=new Label("请输入单词:");
TextField t1=new TextField(4);
Button b1=new Button("大写");
Label l2=new Label("此处显示大写单词");

public void init()
{
add(l1);
add(t1);
add(b1);
add(l2);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
String s=t1.getText();
String upperCase=s.toUpperCase();
l2.setText(upperCase);
}

}
为什么不用这种方法呢???

Label l2=new Label("此处显示大写单词");
} <-大括号放到程序最后
还有把implements ActionListener 去掉
就可以了