饭卡管理系统(java)

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

package mysql;

import java.awt.*;

import java.awt.event.*;

import java.sql.*;

import javax.swing.*;

class Login extends JFrame

{

private static final long serialVersionUID = 1L;

private static JFrame frame = new JFrame("学生饭卡管理系统登录界面");

private JButton submit = new JButton("登陆");

private JButton reset = new JButton("重置");

private JButton assign=new JButton("注册");

JLabel nameLab = new JLabel("用户名:");

private JLabel passwdLab = new JLabel("密码:");

private JLabel lab = new JLabel();

public JTextField nameText = new JTextField(20);

public JPasswordField passwdText = new JPasswordField(20);

public Login(){}

public void login(){

nameLab.setBounds(60, 20, 100,20);

passwdLab.setBounds(60, 50, 100,20);

lab.setBounds(100, 90, 200,20);

nameText.setBounds(120, 20, 100, 20);

passwdText.setBounds(120, 50, 100, 20);

submit.setBounds(120, 120, 100, 30);

reset.setBounds(250, 50, 60, 20);

assign.setBounds(250,20,60,20);

//passwdText.setEchoChar('*');

frame.add(nameLab);

frame.add(passwdLab);

frame.add(lab);

frame.add(nameText); //用户名

frame.add(passwdText); //用户密码

frame.add(submit);

frame.add(reset);

frame.add(assign);

frame.setSize(400, 220);

frame.setLocation(400, 250);

ImagePanel img = new ImagePanel();

img.setBounds(0,0,400,200);

frame.add(img);

frame.setVisible(true);

submit.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

@SuppressWarnings("deprecation")

String passwd=passwdText.getText().toString();

String name=nameText.getText();

try{

ResultSet sqlRst=null;

Class.forName("com.mysql.jdbc.Driver");

Connection

conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/test1","root","123456");

Statement st= conn.createStatement();

String sql = "select * from user where name='"+name+"' and passwd='"+passwd+"';";

sqlRst=st.executeQuery(sql);

if(sqlRst.next()){

frame.dispose();

new Fankajiemain();

}

else{

lab.setForeground(Color.red);

lab.setText("登陆失败! 密码或账号错误!");

}

}catch(ClassNotFoundException e1){

e1.printStackTrace();

} catch (SQLException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

}

});

assign.addActionListener(new ActionListener(){ // 注册按钮,点击进入到第三层界面输入学号

public void actionPerformed(ActionEvent e){

frame.dispose();

new Zhuce();

}

}

);

reset.addActionListener(new ActionListener(){ // 重置按钮

public void actionPerformed(ActionEvent e){

nameText.setText(""); //用户名重置

passwdText.setText(""); //密码重置

}

}

);

}

public static void main(String args[]) {

Login log= new Login();

log.login();

}

class ImagePanel extends JLabel{ //构建一个图片容器

private static final long serialVersionUID = 1L;

protected void paintComponent(Graphics g){

super.paintComponent(g);

ImageIcon img = new ImageIcon("D:\\Login.jpg");

g.drawImage(img.getImage(),0,0,this);

}

}

}

相关文档
最新文档