1、源代码登陆界面class Login extends JFrame implements ActionListener Container cp=null; JFrame f=null; JButton j1,j2; JTextField t1; JPasswordField t2; JLabel jlable1,jlable2; Color c; JPanel jp1,jp2; public void confirm()/验证用户和密码是否存在 tryClass.forName(sun.jdbc.odbc.JdbcOdbcDriver); catch(ClassNotFoundExcepti
2、on e)System.out.println(加载驱动程序失败!); tryString url = jdbc:odbc:driver=Microsoft Access Driver (*.mdb);DBQ=Book.mdb;/直接使用当前类目录下的数据库文件 Connection con=DriverManager.getConnection(url); Statement sql=con.createStatement(); String uname=t1.getText().trim(); String Mima=t2.getText().trim(); String queryMim
3、a=select * from user where 用户名=+uname+ and 密码=+Mima+; ResultSet rs=sql.executeQuery(queryMima); if(rs.next() new Book(uname); f.hide(); con.close(); elseJOptionPane.showMessageDialog(null,该用户不存在,提示!, JOptionPane.YES_NO_OPTION); t1.setText(); t2.setText(); catch(SQLException g) System.out.println(E C
4、ode+g.getErrorCode(); System.out.println(E M+g.getMessage(); 主界面class Book extends JFrame implements ActionListener JButton QueryBook=new JButton(期刊查询); JButton BookIn=new JButton(期刊入库); JButton RemoveBook=new JButton(期刊删除); JButton BookBrower=new JButton(期刊概览); JButton UpdateMima=new JButton(修改密码);
5、 JMenuBar mb = new JMenuBar();/菜单栏 JPanel jp=new JPanel();/用来填放子模块 Container cp=getContentPane();String username;Book(String username) this.username=username; mb.add(QueryBook); mb.add(BookIn); mb.add(RemoveBook); mb.add(BookBrower); mb.add(UpdateMima); cp.add(mb,North); jp.setBorder(BorderFactory.c
6、reateTitledBorder(BorderFactory.createLineBorder(Color.blue, 2),null,TitledBorder.CENTER, TitledBorder.TOP); jp.setLayout(new BorderLayout(); JLabel label1 = new JLabel(new ImageIcon(4.jpg); jp.add(label1);JLabel JL=new JLabel(欢迎登陆,SwingConstants.CENTER); jp.add(JL,North); JScrollPane scrollpane=new
7、 JScrollPane(jp); cp.add(scrollpane); setTitle(欢迎登陆); Toolkit kit=Toolkit.getDefaultToolkit(); Dimension screen=kit.getScreenSize(); int x=screen.width; /*取得显示器窗口的宽度*/ int y=screen.height; /*取得显示器窗口的高度*/ /setSize(x,y); /*让系统窗口平铺整个显示器窗口*/ setSize(600,600); int xcenter=(x-600)/2; int ycenter=(y-600)/2
8、; setLocation(xcenter,ycenter);/*显示在窗口中央*/ setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); /注册临听器 QueryScore.addActionListener(this); QueryXuefen.addActionListener(this); jiangfa.addActionListener(this); xuanke.addActionListener(this); gaiMima.addActionListener(this); public void a
9、ctionPerformed(ActionEvent e) String cmd=e.getActionCommand(); if (cmd.equals(期刊查询)new QueryBook(); if (cmd.equals(期刊入库)new BookIn();if (cmd.equals(期刊删除)new RemoveBook();if (cmd.equals(期刊概览)new BookBrower().showRecord(); if (cmd.equals(期刊密码)new UpdateMima(username);期刊入库class BookIn implements Action
10、Listener JFrame f3; Container cp; JPanel jp1,jp2,jp3,jp4,jp,jpanelWest; JButton jbt1,jbt2;/按钮:确定、取消、 JLabel label; /标签 JTextField tf1,tf2,tf3,tf4,tf5,tf6; /定义文本框 JLabel label1,label2,label3,label4; String sno; public void insertRecord() if(tf1.getText().equals()|tf2.getText().equals()|tf3.getText().
11、equals()|tf4.getText().equals()|tf5.getText().equals()|tf6.getText().equals() JOptionPane.showMessageDialog(f3,请填写图书资料); return; tryClass.forName(sun.jdbc.odbc.JdbcOdbcDriver); catch(ClassNotFoundException e)System.out.println(加载驱动程序失败!); try String url = jdbc:odbc:driver=Microsoft Access Driver (*.
12、mdb);DBQ=Book.mdb;/直接使用当前类目录下的数据库文件 Connection con=DriverManager.getConnection(url); Statement sql; String s=insert into book values(+tf1.getText()+,+tf2.getText()+,+tf3.getText()+,+tf4.getText()+,+tf5.getText()+,+tf6.getText()+);/查询输入的图书号是否在数据库中存在 String query=select * from book where 期刊号=+tf2.getT
13、ext()+; sql=con.createStatement(); ResultSet rs=sql.executeQuery(query);/返回查询结果集 boolean moreRecords=rs.next();/判断结果集是否有数据 if(moreRecords) JOptionPane.showMessageDialog(f3,期刊号已经被使用,请重新输入);con.close(); tf2.setText(); return; int insert=sql.executeUpdate(s); if(insert=1) JOptionPane.showMessageDialog(
14、null,期刊信息录入成功!); tf1.setText(); tf2.setText(); tf3.setText(); tf4.setText(); tf5.setText(); tf6.setText(); catch(SQLException g) System.out.println(E Code+g.getErrorCode(); System.out.println(E M+g.getMessage();期刊借阅class BookBrower implements ActionListener JFrame f; Container cp; JPanel jpS,jpanelW
15、est; JButton jbt1,jbt2;/按钮,确定,返回 JLabel label,L; /标签 JTable table;/用来接收数据库中返回的信息 Object columnName=期刊名,期刊号,单价,作者,出版社,入库时间; Object ar =new Object806; String sno; String count=xx; public void showRecord() while(i=0) ari0=; ari1=; ari2=; ari3=; ari4=; ari5=; i-; i=0; tryClass.forName(sun.jdbc.odbc.Jdbc
16、OdbcDriver); catch(ClassNotFoundException e)System.out.println(加载驱动程序失败!); tryString url = jdbc:odbc:driver=Microsoft Access Driver (*.mdb);DBQ=Book.mdb;/直接使用当前类目录下的数据库文件 Connection con=DriverManager.getConnection(url); String s=select * from book ; Statement sql=con.createStatement(); ResultSet rs=
17、sql.executeQuery(s); while(rs.next() String bname=rs.getString(1); String bno=rs.getString(2); String price=rs.getString(3); String writer=rs.getString(4); String publish=rs.getString(5); String indate=rs.getString(6); ari0=bname; ari1=bno; ari2=price; ari3=writer; ari4=publish; ari5=indate; i+; cou
18、nt=+i+; L.setText(书库现在共有期刊+count+本); f.repaint(); con.close(); catch(SQLException g) System.out.println(E Code+g.getErrorCode(); System.out.println(E M+g.getMessage();期刊删除class RemoveBook implements ActionListener JFrame f; Container cp; JPanel jpS,jpanelWest; JButton jbt1,jbt2,jbt3;/按钮,查询、取消、修改 JLa
19、bel label,L; /标签:请输入学号 JTextField tf; /定义文本框 JTable table;/用来接收数据库中返回的信息 Object columnName=期刊名,期刊号,单价,作者,出版社,入库时间; Object ar =new Object806; String count=xx; public void showRecord(String ql) while(i=0) ari0=; ari1=; ari2=; ari3=; ari4=; ari5=; i-; i=0;tryClass.forName(sun.jdbc.odbc.JdbcOdbcDriver);
20、 catch(ClassNotFoundException e)System.out.println(加载驱动程序失败!); try String url = jdbc:odbc:driver=Microsoft Access Driver (*.mdb);DBQ=Book.mdb;/直接使用当前类目录下的数据库文件 Connection con=DriverManager.getConnection(url); Statement sql; String s=select * from book where 期刊名 =+ql +; sql=con.createStatement(); Res
21、ultSet rs=sql.executeQuery(s); while(rs.next() String bname=rs.getString(1); String bno=rs.getString(2); String price=rs.getString(3); String writer=rs.getString(4); String publish=rs.getString(5); String indate=rs.getString(6); ari0=bname; ari1=bno; ari2=price; ari3=writer; ari4=publish; ari5=indat
22、e; i+; count=+i+; L.setText(该种期刊共有+count+本); f.repaint(); con.close();System.out.println(ar01); catch(SQLException g) System.out.println(E Code+g.getErrorCode(); System.out.println(E M+g.getMessage(); public void deleteRecord(int index) tryClass.forName(sun.jdbc.odbc.JdbcOdbcDriver);catch(ClassNotFo
23、undException e)System.out.println(加载驱动程序失败!); tryString url = jdbc:odbc:driver=Microsoft Access Driver (*.mdb);DBQ=Book.mdb;/直接使用当前类目录下的数据库文件 Connection con=DriverManager.getConnection(url); Statement sql; String ql=(String)(arindex1); String s=delete * from book where 期刊号 =+ql +; sql=con.createStat
24、ement(); int del=sql.executeUpdate(s); if(del=1) JOptionPane.showMessageDialog(null,删除成功!, 信息, JOptionPane.YES_NO_OPTION); con.close(); f.repaint(); catch(SQLException g) System.out.println(E Code+g.getErrorCode(); System.out.println(E M+g.getMessage(); 期刊查询class QueryBook implements ActionListener
25、JFrame f3; Container cp; JPanel jp1,jp2,jp3,jp4,jp,jpanelWest; JButton jbt1,jbt2;/按钮,确定、取消 JLabel label; /标签:请输入期刊号 JTextField tf,tf1,tf2,tf3,tf4,tf5,tf6; /定义文本框 JLabel label1,label2,label3,label4;public void showRecord() tryClass.forName(sun.jdbc.odbc.JdbcOdbcDriver); catch(ClassNotFoundException e
26、)System.out.println(加载驱动程序失败!);tryString url = jdbc:odbc:driver=Microsoft Access Driver (*.mdb);DBQ=Book.mdb;/直接使用当前类目录下的数据库文件 Connection con=DriverManager.getConnection(url); Statement sql; String ql=tf.getText().trim(); String s=select * from book where 期刊号 =+ql +; sql=con.createStatement(); Resul
27、tSet rs=sql.executeQuery(s); if(rs.next() String bname=rs.getString(1); String bno=rs.getString(2); String price=rs.getString(3); String writer=rs.getString(4); String publish=rs.getString(5); String indate=rs.getString(6); tf1.setText(bname); tf2.setText(bno); tf3.setText(price); tf4.setText(writer); tf5.setText(publish); tf6.setText(indate); else JOptionPane.showMessageDialog(null,您输入的期刊号不存在,请重新输入, 输入错误, JOptionPane.YES_NO_OPTION); con.close(); catch(SQLException g) System.out.println(E Code+g.getErrorCode(); System.out.println(E M+g.getMessage(); tf1.setEditable(false); tf
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1