用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字

花花shij    -  云代码空间

——

登录

2017-11-02|790阅||

摘要:import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.sql.*; public class Login implements ActionListener{


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class Login implements ActionListener{
 private JFrame app;
 private JButton 登录,退出;
 private JLabel jl1,jl2,jl3;
 private JPanel jp1,jp2,jp3,jp4;
 public static JTextField jt1;
 private JPasswordField jpf1,jpf2;
 private JDialog jd;
 private int message=0;
 public static ResultSet rs;
 public Login(){
  app=new JFrame("TankWar2.0");
  app.setSize(350,200);
  app.setLocation(360,240);
  app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  Container c=app.getContentPane();
  c.setLayout(new GridLayout(4,1));
  jl1=new JLabel("用户账号");
  jt1=new JTextField(10);
  jp1=new JPanel();
  jp1.add(jl1);
  jp1.add(jt1);
  c.add(jp1);
  jl2=new JLabel("用户密码");
  jpf1=new JPasswordField(10);
  jp2=new JPanel();
  jp2.add(jl2);
  jp2.add(jpf1);
  c.add(jp2);
  jl3=new JLabel("确认密码");
  jpf2=new JPasswordField(10);
  jp3=new JPanel();
  jp3.add(jl3);
  jp3.add(jpf2);
  c.add(jp3);
  jd=new JDialog();
  jd.setSize(340,80);
  jd.setLocation(app.getX()+100,app.getY()+100);
  jd.setLayout(new FlowLayout());  
  退出=new JButton("退出");
  退出.addActionListener(new ActionListener(){
   public void actionPerformed(ActionEvent event){
    System.exit(0);
   }
  }
    );
  登录=new JButton("登录");
  登录.addActionListener(this);
  jp4=new JPanel();  
  jp4.add(退出);
  jp4.add(登录);
  c.add(jp4);
  app.setVisible(true);
  jp1.setBackground(Color.PINK);
  jp2.setBackground(Color.PINK);
  jp3.setBackground(Color.PINK);
  jp4.setBackground(Color.PINK);
  app.setLocationRelativeTo(null);
 }
 public void actionPerformed(ActionEvent e){
  if(e.getSource()==登录){
   
   
   try {
    Class.forName("com.mysql.jdbc.Driver");
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/tankwar?characterEncoding=utf-8","root","hua");
    String sql="select * from records";
    Statement stmt = con.createStatement(); 
    String st1=null;
    String st2=null;
    
    rs=stmt.executeQuery(sql);
    while(rs.next()){
     st1=rs.getString(1);
     st2=rs.getString(2);
    
     if((jt1.getText().equals(st1)) && (jpf1.getText().equals(st2))&&(jpf2.getText().equals(jpf1.getText()))){
      message=1;
      app.setVisible(false);
      JOptionPane.showMessageDialog(app, "输入正确,欢迎使用本系统","系统提示",JOptionPane.INFORMATION_MESSAGE);
      new FirstFrame().setVisible(true);
      app.dispose();
      
      con.close();
      
      
     }
     
    }
    {
     JOptionPane.showMessageDialog(null, "错误", "系统提示", JOptionPane.ERROR_MESSAGE);
    }
   }catch(Exception  e2){
    System.out.println(e2.getStackTrace());
  }
  }
 }
 public static void main(String[] args) {
  new Login();
 }
}
顶 0踩 0收藏
文章评论
    发表评论

    个人资料

    • 昵称: 花花shij
    • 等级: 初级程序员
    • 积分: 12
    • 代码: 0 个
    • 文章: 7 篇
    • 随想: 0 条
    • 访问: 4 次
    • 关注

    人气文章

    人气代码

      最新提问

        站长推荐