日期:2014-05-20 浏览次数:20961 次
import java.util.regex.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
class denglu extends Frame// implements ActionListener
{
// String s1[]=new String[5];
private Box baseBox,boxv1,boxv2;
private Panel p1,p2,p3;
private TextField text1,text2;
private Label l1,l2,l3;
private Button submit,reset;
// denglu(TextField t1,TextField t2){
// this.t1 = t1;
// this.t2 = t2;
// }
denglu(){
l1 = new Label("请登录到杨海主页!");
l2 = new Label("账号:");
l3 = new Label("密码:");
submit =new Button("提交");
reset = new Button("重置");
text1 = new TextField(16);
text2 = new TextField(16);
p1 = new Panel();
p2 = new Panel();
p3 = new Panel();
p1.add(l1);
p3.add(submit);p3.add(reset);
//p2.setLayout(new GridLayout(2,1));
// p2.add(l2);p2.add(text1);
// p2.add(l3);p2.add(text2);
// add(p2,"Center");
boxv1 = Box.createVerticalBox();
boxv1.add(new JLabel("账号:"));
boxv1.add(Box.createVerticalStrut(8));
boxv1.add(new JLabel("密码:"));
// boxv1.add(Box.createVerticalStrut(8));
boxv2 = Box.createVerticalBox();
boxv2.add(text1);
boxv2.add(Box.createVerticalStrut(8));
boxv2.add(text2);
baseBox = Box.createHorizontalBox();
baseBox.add(boxv1);
// baseBox.add(Box.createHorizontalStrut(10));
baseBox.add(boxv2);
p2.setLayout(new FlowLayout());
p2.add(baseBox);
add(p2,"Center");add(p1,"North");add(p3,"South");
// setLayout(new FlowLayout());
// addWindowListener(this);
myevent();
setSize(400,500);
setVisible(true);
}
public void text(){
String s = null;
try{
FileReader fr = new FileReader("1.txt");
int b=0;
char[]buf = new char[1024];
while((b=fr.read())!=-1)
s = new String(buf,0,b);
// System.out.println(new String(buf,0,b));
}
catch(IOException e1){}
String a = " ";
String sa[] = s.split(a);
String s1 = text1.getText();
String s2 = text2.getText();
// String a1 ="[a-z]{6,10}";
String a2 ="\\w{6,10}";
// boolean flag1 = s1.matches(a1);
boolean flag2 = s2.matches(a2);
// if(!flag1)
// JOptionPane.showMessageDialog(this,"您输入了非法字符","警告提示框",
// JOptionPane.WARNING_MESSAGE);
if(!flag2)
JOptionPane.showMessageDialog(this,"密码输入错误!","警告提示框",
JOptionPane.WARNING_MESSAGE);
else if(!(s1.equals(sa[0])||!(s2.equals(sa[4]))))
JOptionPane.showMessageDialog(this,"密码或账号输入错误!","警告提示框",
JOptionPane.WARNING_MESSAGE);
else
new hello();
}
public void myevent(){
submit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
text();
// String s1 = text1.getText();
// String s2 = text2.getText();
}
});
reset.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(e.getSource()==reset){
text1.setText(null);
text2.setText(null);
}
}
});
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
//System.exit(0);
setVisible(false);
}
});
}
/* public static void main(String[] args)
{
new denglu();
System.out.println("Hello World!");
}*/
}