jbt2.addActionListener(this);
/*f3.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){ System.exit(0); } } );*/ }
//------------------------------------------------ public void insertRecord() {
if(tf1.getText().equals(\||
tf4.getText().equals(\ {
JOptionPane.showMessageDialog(f3,\请填写图书资料\ return; }
try{
Class.forName(\
}catch(ClassNotFoundException e){System.out.println(\加载驱动程序失败!\
try{
String url = \Access Driver (*.mdb)};DBQ=Book.mdb\直接使用当前类目录下的数据库文件 Connection con=DriverManager.getConnection(url); Statement sql;
String s=\into book values('\
tf3.getText()+\');\
//查询输入的图书号是否在数据库中存在
String query=\图书号='\ sql=con.createStatement();
ResultSet rs=sql.executeQuery(query);//返回查询结果集 boolean moreRecords=rs.next();//判断结果集是否有数据
26
if(moreRecords) {
JOptionPane.showMessageDialog(f3,\图书号已经被使用,请重新输入\
con.close(); tf2.setText(\ return; }
int insert=sql.executeUpdate(s); if(insert==1) {
JOptionPane.showMessageDialog(null,\图书信息录入成功!\ tf1.setText(\ tf2.setText(\ tf3.setText(\ tf4.setText(\ tf5.setText(\ tf6.setText(\ }
}catch(SQLException g) {
System.out.println(\ System.out.println(\ }
}
public void actionPerformed(ActionEvent e) {
String cmd=e.getActionCommand(); if(cmd.equals(\确定\ {
insertRecord(); }
else if(cmd.equals(\取消\ f3.hide(); }
27
public static void main(String []arg){
BookIn a=new BookIn(); } }
6主界面:程序名Book.java /*本类为用户界面*/
import java.net.*; import java.sql.*; import java.awt.*;
import java.awt.event.*; import java.io.*; import java.util.*; import javax.swing.*;
import javax.swing.border.*;import java.util.*;
class Book extends JFrame implements ActionListener {
JButton QueryScore=new JButton(\图书查询\ JButton QueryXuefen=new JButton(\图书入库\ JButton jiangfa=new JButton(\图书删除\ JButton xuanke=new JButton(\图书概览\ JButton gaiMima=new JButton(\修改密码\ JMenuBar mb = new JMenuBar();//菜单栏 JPanel jp=new JPanel();//用来填放子模块 Container cp=getContentPane(); String username; Book(){}
Book(String username) {
this.username=username; mb.add(QueryScore); mb.add(QueryXuefen); mb.add(jiangfa); mb.add(xuanke); mb.add(gaiMima); cp.add(mb,\
// 设置边框
jp.setBorder(BorderFactory.createTitledBorder(BorderFactory .createLineBorder(Color.blue, 2),null, TitledBorder.CENTER, TitledBorder.TOP)); jp.setLayout(new BorderLayout());
28
JLabel label1 = new JLabel(new ImageIcon(\ jp.add(label1);
/* JLabel JL=new JLabel(\欢迎登陆\ jp.add(JL,\
JLabel label2 = new JLabel(new ImageIcon(\ //jp.add(label2,\
JScrollPane scrollpane=new 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;
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 actionPerformed(ActionEvent e) {
String cmd=e.getActionCommand(); if (cmd.equals(\图书查询\ {
new QueryBook(); }
if (cmd.equals(\图书入库\ {
new BookIn(); }
if (cmd.equals(\图书删除\
29
{
new RemoveBook(); }
if (cmd.equals(\图书概览\ {
new BookBrower().showRecord(); }
if (cmd.equals(\修改密码\ {
new UpdateMima(username); }
}
public static void main(String[]args) {
new Book(\ } }
7.密码修改:程序名UpdateMima.java import java.net.*; import java.sql.*; import java.awt.*;
import java.awt.event.*; import java.io.*; import java.util.*; import javax.swing.*;
class UpdateMima extends JFrame implements ActionListener {
JFrame f; Container cp;
JPanel jp1,jp2,jp3,jp4,jp,jpanelWest; JButton jbt1,jbt2;//按钮,确定、取消
JLabel label; //标签:修改密码 JTextField name;
JPasswordField tf1,tf2,tf3; //定义文本框 JLabel label1,label2,label3,label4;
30