java程序请教高手

来源:百度知道 编辑:UC知道 时间:2024/05/09 16:33:14
package testtextfield;
import java.awt.*;
import java.awt.event.*;

public class testTextField{
public static void main(String args[]){
frame myframe=new frame();
}
}
class frame extends Frame implements ActionListener{
Label label1;
Label label2;
TextField username;
TextField password;
Button button;
Label cue;
public frame(){
super("Enter System");
this.setLayout(new FlowLayout());
Label label1=new Label("Username");
TextField username=new TextField(10);
Label label2=new Label("Password");
TextField password=new TextField(10);
password.setEchoChar('*');
Button button=new Button("submit");
Label cue=new Label("Please enter!");
button.addActionListener(this);
this.setBackground(Color.LIGHT_GRAY);

this.add(label1);
this.add(username);

你的frame()构造方法里重定义了,去掉所有重定义声明。例如
Label label1=new Label("Username");
TextField username=new TextField(10);
Label label2=new Label("Password");
TextField password=new TextField(10);
password.setEchoChar('*');
Button button=new Button("submit");
Label cue=new Label("Please enter!");
变成:!!!!!!!!!!!!

label1=new Label("Username");
username=new TextField(10);
label2=new Label("Password");
password=new TextField(10);
password.setEchoChar('*');
button=new Button("submit");
cue=new Label("Please enter!");

没有监听按钮点击事件。