1、饭卡管理系统javapackage 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 rese
2、t = 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()pu
3、blic 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
4、); /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.setBoun
5、ds(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.
6、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(
7、); 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 actionPerforme
8、d(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 extend
9、s 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); package mysql;import java.awt.*;import javax.swing.*;import java.awt.event.ActionEv
10、ent;import java.awt.event.ActionListener;import java.sql.Connection;import java.sql.DriverManager;import java.sql.SQLException;import java.sql.Statement;class Zhuce private JFrame jrf=new JFrame(注册窗口); private JLabel jla1=new JLabel(用户名:); private JLabel jla2=new JLabel(密 码:); private JLabel jla3=ne
11、w JLabel(确认密 码:); private JLabel jla4=new JLabel(姓名:); private JLabel jla5=new JLabel(性别:); private JLabel jla6=new JLabel(年龄:); private JLabel jla7=new JLabel(生日:); private JLabel jla8=new JLabel(身份证:); private JLabel jla9=new JLabel(班级:); private JLabel jla10=new JLabel(学院:); private JLabel jla13=
12、new JLabel(金额:); private JLabel jla14=new JLabel(余额:); private JLabel jla11=new JLabel( ); private JLabel jla12=new JLabel(xxxx-xx-xx); /日期的格式 private JTextField jtx1=new JTextField(); private JTextField jtx2=new JTextField(); private JTextField jtx3=new JTextField(); private JTextField jtx4=new JTe
13、xtField(); private JTextField jtx5=new JTextField(); private JTextField jtx6=new JTextField(); private JTextField jtx7=new JTextField(); private JTextField jtx8=new JTextField(); private JTextField jtx9=new JTextField(); private JTextField jtx10=new JTextField(); private JTextField jtx13=new JTextFi
14、eld(); private JTextField jtx14=new JTextField(); private JButton jbt=new JButton(提交); private JButton jbt1=new JButton(返回); Zhuce() Container cp=jrf.getContentPane(); /jrf.setBounds(500,200,300,300); jla1.setBounds(40,20,100,20); jla2.setBounds(40,60,100,20); jla3.setBounds(40,100,100,20); jla4.set
15、Bounds(40,140,100,20); jla5.setBounds(40,180,100,20); jla6.setBounds(40,220,100,20); jla7.setBounds(40,260,100,20); jla8.setBounds(40,300,100,20); jla9.setBounds(40,340,100,20); jla10.setBounds(40,380,100,20); jla11.setBounds(120,500,150,20); jla12.setBounds(270,260,100,20); jla13.setBounds(40,420,1
16、00,20); jla14.setBounds(40,460,100,20); jtx1.setBounds(110,20,150,20); jtx2.setBounds(110,60,150,20); jtx3.setBounds(110,100,150,20); jtx4.setBounds(110,140,150,20); jtx5.setBounds(110,180,150,20); jtx6.setBounds(110,220,150,20); jtx7.setBounds(110,260,150,20); jtx8.setBounds(110,300,150,20); jtx9.s
17、etBounds(110,340,150,20); jtx10.setBounds(110,380,150,20); jtx13.setBounds(110,420,150,20); jtx14.setBounds(110,460,150,20); jbt.setBounds(90,550,80,30); jbt1.setBounds(190,550,80,30); cp.add(jla1); cp.add(jla2); cp.add(jla3); cp.add(jla4); cp.add(jla5); cp.add(jla6); cp.add(jla7); cp.add(jla8); cp.
18、add(jla9); cp.add(jla10); cp.add(jla13); cp.add(jla14); cp.add(jla11); /提醒注册错误 cp.add(jla12); cp.add(jtx1); cp.add(jtx2); cp.add(jtx3); cp.add(jtx4); cp.add(jtx5); cp.add(jtx6); cp.add(jtx7); cp.add(jtx8); cp.add(jtx9); cp.add(jtx10); cp.add(jtx13); cp.add(jtx14); cp.add(jbt); cp.add(jbt1); cp.setLa
19、yout(null); ImagePan img = new ImagePan(); img.setBounds(0,0,400,600); jrf.add(img); jrf.setSize(400,640); jrf.setLocation(450, 40); jrf.setVisible(true); jbt.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) try Class.forName(com.mysql.jdbc.Driver); Connection conn=D
20、riverManager.getConnection(jdbc:mysql:/localhost:3306/test1,root,123456); Statement st= conn.createStatement(); String sql = insert into user(userNo,passwd)values(+jtx1.getText()+,+jtx2.getText()+); String sql1 = insert into student values(+jtx1.getText()+,+jtx4.getText()+,+jtx5.getText()+,+jtx6.get
21、Text()+,+jtx7.getText()+,+jtx8.getText()+,+jtx9.getText()+,+jtx10.getText()+,+jtx13.getText()+,+jtx14.getText()+); if(jtx2.getText().compareTo(jtx3.getText()=0)&(String)(jtx2.getText().length()0&(String)(jtx1.getText().length()0) jla11.setForeground(Color.blue); jla11.setText(注册成功!); st.executeUpdat
22、e(sql); st.executeUpdate(sql1); jrf.setVisible(true); else jla11.setForeground(Color.red); jla11.setText(注册失败!); catch(ClassNotFoundException e1) e1.printStackTrace(); catch (SQLException e1) / TODO Auto-generated catch block e1.printStackTrace(); jrf.setVisible(true); ); jbt1.addActionListener(new
23、ActionListener() public void actionPerformed(ActionEvent e) jrf.dispose(); Login l= new Login(); l.login(); ); public static void main(String args)throws SQLException, ClassNotFoundException new Zhuce(); class ImagePan extends JLabel /构建一个图片容器 private static final long serialVersionUID = 1L; protect
24、ed void paintComponent(Graphics g) super.paintComponent(g); ImageIcon icon = new ImageIcon(D:Eclipsezhuce.jpg); g.drawImage(icon.getImage(),0,0,this); package mysql;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class Fankajiemain extends Login implements ActionListener /* * *
25、/ private static final long serialVersionUID = 1L; SuppressWarnings(deprecation) String passwd=passwdText.getText().toString(); String name=nameText.getText(); private JFrame frame = new JFrame(学生饭卡管理系统); Container cp = frame.getContentPane(); private JLabel user_name=new JLabel(name); private JLabe
26、l jtx_hu=new JLabel(欢迎您:); JMenuBar mb = new JMenuBar(); JMenu menu1 = new JMenu(管理); JMenuItem mi2= new JMenuItem(退出); JMenu menu2 = new JMenu(信息维护); JMenuItem mi2_1 = new JMenuItem(密码修改); JMenuItem mi2_2 = new JMenuItem(更改信息); JMenu menu3= new JMenu(信息查询); JMenuItem mi3_1 = new JMenuItem(个人信息); Fa
27、nkajiemain() / user_name.setText(name); mb.add(menu1); mb.add(menu2); mb.add(menu3); menu1.add(mi2); menu2.add(mi2_1); menu2.add(mi2_2); menu3.add(mi3_1); mi2.addActionListener(this); mi2_1.addActionListener(this); mi2_2.addActionListener(this); mi3_1.addActionListener(this); user_name.setBounds(800
28、,20,200,20); jtx_hu.setBounds(750,20,200,20); frame.add(user_name); frame.add(jtx_hu); frame.setSize(900, 700); frame.setJMenuBar(mb); frame.setLocation(250, 20); ImagePanel img = new ImagePanel(); img.setBounds(0,0,400,200); frame.add(img); frame.setVisible(true); mi2.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) frame.dispose(); ); mi2_1.addActionListener(new Ac
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1