packagecom.view;
importjava.awt.*;
importjavax.imageio.ImageIO;
importjavax.swing.*;
importjavax.swing.border.Border;
importcom.model.LoginModel;
importcom.sun.jndi.url.ldaps.ldapsURLContextFactory;
importcom.tools.ImagePanel;
importcom.tools.QrcodeUtil;
importcom.tools.Tools;
importcom.tools.YanZhengma;
importjava.awt.event.*;
importjava.io.*;
importjava.util.Random;
importjava.util.Scanner;
publicclassLoginextendsJFrameimplementsActionListener,KeyListener{
booleanisBreak=false;;
ImagePanelip;
JTextFieldjtf,jtf1;
JPasswordFieldjpf;
JLabeljbl1,jbl2,jbl3;
JButtonjb1,jb2;
publicLogin(){
ImagebackImage=null;
try{
backImage=ImageIO.read(newFile("image/background.jpg"));
}catch(IOExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
ip=newImagePanel(backImage);
ip.setLayout(null);
jbl1=newJLabel("用户名:");
jbl1.setFont(Tools.f1);
jbl1.setBounds(260,130,50,22);
jbl2=newJLabel("密码:");
jbl2.setFont(Tools.f1);
jbl2.setBounds(260,170,50,22);
jbl3=newJLabel(""+this.yanZm()+"");
jbl3.setBounds(260,210,50,22);
jbl3.setFont(Tools.f3);
jbl3.setOpaque(true);
jbl3.setBackground(Color.DARK_GRAY);
jbl3.setForeground(Color.white);
jtf=newJTextField();
jtf.setBounds(315,130,150,22);
jtf.setBorder(BorderFactory.createLoweredBevelBorder());
jpf=newJPasswordField();
jpf.setBounds(315,170,150,22);
jpf.setBorder(BorderFactory.createLoweredBevelBorder());
jtf1=newJTextField();
jtf1.setBounds(315,210,150,22);
jtf1.setBorder(BorderFactory.createLoweredBevelBorder());
jb1=newJButton("登录");jb1.addActionListener(this);
jb1.setFont(Tools.f1);
jb1.setBounds(315,250,70,22);
jb2=newJButton("退出");jb2.addActionListener(this);
jb2.setFont(Tools.f1);
jb2.setBounds(395,250,70,22);
ip.add(jbl1);
ip.add(jbl2);
ip.add(jbl3);
ip.add(jtf);
ip.add(jpf);
ip.add(jtf1);
ip.add(jb1);
ip.add(jb2);
this.add(ip);
this.setSize(513,331);
this.setLocation(Tools.w/2-250,Tools.h/2-170);
this.setResizable(false);
this.setUndecorated(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
jtf1.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvente){
jb1.doClick();
}
});
}
publicvoidactionPerformed(ActionEventarg0){
//TODOAuto-generatedmethodstub
if(arg0.getSource()==jb2){
this.dispose();
}elseif(arg0.getSource()==jb1){
Stringu=jtf.getText().toString().trim();
Stringp=newString(jpf.getPassword());
Stringl=jbl3.getText().toString().trim();
Stringr=jtf1.getText().toString().trim();
if(l.equalsIgnoreCase(r)){
LoginModellm=newLoginModel();
if(lm.checkUser(u,p)){
newMainFrame();
this.dispose();
}else{
this.clear();
}
}else{
JOptionPane.showMessageDialog(null,"验证码错误");
}
}
}
publicvoidclear(){
jtf.setText("");
jpf.setText("");
jtf1.setText("");
}
publicStringyanZm(){
Stringtext="";
YanZhengmayzh=newYanZhengma();
text=yzh.random(4);
returntext;
}
publicvoidkeyTyped(KeyEvente){
//TODOAuto-generatedmethodstub
}
publicvoidkeyPressed(KeyEvente){
//TODOAuto-generatedmethodstub
}
publicvoidkeyReleased(KeyEvente){
//TODOAuto-generatedmethodstub
if(e.getKeyText(e.getKeyCode()).compareToIgnoreCase("Enter")==0)
{
jb1.doClick();
}
}
publicstaticvoidmain(String[]args){
newLogin();
}
}
分 -->
|