
请教电脑高手 帮帮忙 看看这个程序错在哪里 调试无错 但是运行发生异常!!
importjava.awt.*;importjava.awt.event.*;classWindowButtonextendsFrameimplementsAction...
import java.awt.*;
import java.awt.event.*;
class WindowButton extends Frame implements ActionListener
{ Label label1,label2,label3,label4;
TextField text1,text2;
Button buttonEnter,buttonCancel;
WindowButton(String s)
{ super(s);
setLayout(new FlowLayout());
label1=new Label("输入用户名:");
label1.setBackground(Color.cyan);
text1=new TextField();
label2=new Label("* 检测用户名 *:");
label3=new Label("输入密码:");
label3.setBackground(Color.cyan);
text2=new TextField();
text2.setEchoChar('*');
label3=new Label("检测密码:");
buttonEnter=new Button("确定");
buttonCancel=new Button("取消");
add(label1);
add(label2);
add(label3);
add(label4);
add(text1);
add(text2);
add(buttonEnter);
add(buttonCancel);
buttonEnter.addActionListener(this);
buttonCancel.addActionListener(this);
text1.addActionListener(this);
text2.addActionListener(this);
setBounds(200,200,200,222);
setVisible(true);
validate();
}
public void actionPerformed(ActionEvent e)
{ if(e.getSource()==text1)
{ String str1=text1.getText();
String regex1="\\w{6,14}";
if(str1.matches(regex1))
{label2.setText("用户名正确");
}
else
{label2.setText("用户名错误");
}
}
if(e.getSource()==text2)
{ String str2=text2.getText();
String regex2="\\w{6,11}";
if((str2.matches(regex2))&&(!str2.matches("_")))
{label4.setText("密码正确");
}
else
{label4.setText("密码错误");
}
}
if(e.getSource()==buttonEnter)
{ String str1=text1.getText();
String regex1="\\w{6,14}";
String str2=text2.getText();
String regex2="\\w{6,11}";
if((str1.matches(regex1))&&(str1.matches(regex2)))
{label4.setText("正在登陆,请稍后........");
}
}
if(e.getSource()==buttonCancel)
{ label4.setText("用户名或密码不能为空");
}
}
}
public class E
{ public static void main(String args[])
{ WindowButton win=new WindowButton("用户登录窗口");
}
} 展开
import java.awt.event.*;
class WindowButton extends Frame implements ActionListener
{ Label label1,label2,label3,label4;
TextField text1,text2;
Button buttonEnter,buttonCancel;
WindowButton(String s)
{ super(s);
setLayout(new FlowLayout());
label1=new Label("输入用户名:");
label1.setBackground(Color.cyan);
text1=new TextField();
label2=new Label("* 检测用户名 *:");
label3=new Label("输入密码:");
label3.setBackground(Color.cyan);
text2=new TextField();
text2.setEchoChar('*');
label3=new Label("检测密码:");
buttonEnter=new Button("确定");
buttonCancel=new Button("取消");
add(label1);
add(label2);
add(label3);
add(label4);
add(text1);
add(text2);
add(buttonEnter);
add(buttonCancel);
buttonEnter.addActionListener(this);
buttonCancel.addActionListener(this);
text1.addActionListener(this);
text2.addActionListener(this);
setBounds(200,200,200,222);
setVisible(true);
validate();
}
public void actionPerformed(ActionEvent e)
{ if(e.getSource()==text1)
{ String str1=text1.getText();
String regex1="\\w{6,14}";
if(str1.matches(regex1))
{label2.setText("用户名正确");
}
else
{label2.setText("用户名错误");
}
}
if(e.getSource()==text2)
{ String str2=text2.getText();
String regex2="\\w{6,11}";
if((str2.matches(regex2))&&(!str2.matches("_")))
{label4.setText("密码正确");
}
else
{label4.setText("密码错误");
}
}
if(e.getSource()==buttonEnter)
{ String str1=text1.getText();
String regex1="\\w{6,14}";
String str2=text2.getText();
String regex2="\\w{6,11}";
if((str1.matches(regex1))&&(str1.matches(regex2)))
{label4.setText("正在登陆,请稍后........");
}
}
if(e.getSource()==buttonCancel)
{ label4.setText("用户名或密码不能为空");
}
}
}
public class E
{ public static void main(String args[])
{ WindowButton win=new WindowButton("用户登录窗口");
}
} 展开
2个回答
展开全部
label3 = new Label("检测密码:");
把label3改为label4 报的空指针异常 lable4是空 所以出错了
把label3改为label4 报的空指针异常 lable4是空 所以出错了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询