




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、Java編寫的簡(jiǎn)單圖書管理系統(tǒng)主界面代碼實(shí)現(xiàn)package Library;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Container;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;im
2、port java.sql.Statement;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JTextField;public class Login extends JFrame private stati
3、c final long serialVersionUID = 1L;private JLabel jlUsername;private JLabel jlPwd;private JTextField txtUsername; /用戶名private JTextField txtPassword; /密碼private JButton jbOk;private JButton jbCancel;public JLabel getJlUsername() if(jlUsername=null)jlUsername=new JLabel(賬號(hào));jlUsername.setForeground(C
4、olor.BLACK);jlUsername.setBounds(118, 40, 85, 30);return jlUsername;public JLabel getJlPwd() if(jlPwd=null)jlPwd=new JLabel(密碼);jlPwd.setForeground(Color.BLACK);jlPwd.setBounds(118, 100, 85, 30);return jlPwd;public JTextField getTxtUsername() if(txtUsername=null)txtUsername=new JTextField(20);txtUse
5、rname.setBounds(180,40 , 200, 30);return txtUsername;public JTextField getTxtPassword() if(txtPassword=null)txtPassword=new JPasswordField(20);txtPassword.setBounds(180, 100, 200, 30);return txtPassword;public JButton getJbOk() if(jbOk=null)jbOk=new JButton(登陸);jbOk.setBounds(150, 180, 90, 30);/jbOk
6、.addActionListener(this);return jbOk;public JButton getJbCancel() if(jbCancel=null)jbCancel=new JButton(取消);jbCancel.setBounds(300, 180, 90, 30);return jbCancel;public Login(String title)super(title);/JFrame frame=new JFrame();Container cantainer=this.getContentPane();this.setDefaultCloseOperation(J
7、Frame.EXIT_ON_CLOSE);ImageIcon img = new ImageIcon(F:Java傳習(xí)srcLibraryZFXYH48I_U)C4M2C4.jpg);/這是背景圖片JLabel imgLabel = new JLabel(img);/將背景圖放在標(biāo)簽里。this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE);/注意這里是關(guān)鍵,將背景標(biāo)簽添加到j(luò)fram的LayeredPane面板里。imgLabel.setBounds(0,0,img.getIconWidth(), img.getI
8、conHeight();/設(shè)置背景標(biāo)簽的位置cantainer.setLayout(new BorderLayout();imgLabel.setLayout(null);imgLabel.add(getJlUsername();imgLabel.add(getTxtUsername();imgLabel.add(getJlPwd();imgLabel.add(getTxtPassword();imgLabel.add(getJbOk();imgLabel.add(getJbCancel();cantainer.add(imgLabel,BorderLayout.NORTH);(JPanel)
9、cantainer).setOpaque(false); /注意這里,將內(nèi)容面板設(shè)為透明。這樣LayeredPane面板中的背景才能顯示出來(lái)。this.setSize(img.getIconWidth(),img.getIconHeight();myEvent();this.setVisible(true);this.setResizable(true);private void myEvent()jbCancel.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)Login.this
10、.dispose(););jbOk.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)Connection conn=null;Statement stm=null;ResultSet st=null;tryClass.forName(com.mysql.jdbc.Driver);conn=DriverManager.getConnection(jdbc:mysql:/localhost:3306/library,sa,123456);stm=conn.createStatement(
11、);String sql=select * from user;/String sql1=select psw from user;st=stm.executeQuery(sql);/ st1=stm.executeQuery(sql1);if(st.next()if(txtUsername.getText().equals(st.getString(id)&txtPassword.getText().equals(st.getString(psw)Login.this.setVisible(false);new Book(管理界面);elseJOptionPane.showMessageDi
12、alog(null, 您輸入的賬號(hào)或密碼不正確);getTxtUsername().setText();getTxtPassword().setText();else JOptionPane.showMessageDialog(null,用戶名不存在,請(qǐng)重新輸入,錯(cuò)誤!); getTxtUsername().setText();getTxtPassword().setText();catch(ClassNotFoundException e1)e1.printStackTrace(); catch (SQLException e2) / TODO Auto-generated catch bl
13、ocke2.printStackTrace();finallytrystm.close();catch (Exception e3) / 關(guān)閉Connection try conn.close(); catch (Exception e4) );public static void main(String args)new Login(圖書管理登陸界面);管理界面實(shí)現(xiàn)代碼package Library;import java.awt.BorderLayout;import java.awt.Container;import java.awt.event.ActionEvent;import j
14、ava.awt.event.ActionListener;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel
15、;import javax.swing.JTable;import javax.swing.JTextField;public class Book extends JFrame private static final long serialVersionUID = 1L;private JLabel lblId;private JLabel lblBname;private JLabel lblWname;private JLabel lblCbs;private JLabel lblnum1;private JLabel lblnum2;private JTextField bId; /
16、圖書編號(hào)private JTextField bname; /書名private JTextField wname; /作者名private JTextField cbs; /出版社private JTextField num1; /現(xiàn)存量private JTextField num2; /庫(kù)存量private JButton jbDel;private JTextField jDel;private JButton jbAdd;private JButton jbSearch;private JButton jbUpdate;private JTable table;private JLab
17、el jabel;/輸入要查找的書號(hào)public JLabel getJabel() if(jabel=null)jabel=new JLabel(查刪學(xué)號(hào));jabel.setBounds(50, 350, 50, 30);return jabel;public JButton getJbDel() if(jbDel=null)jbDel=new JButton(刪除);jbDel.setBounds(180, 400, 60, 30);return jbDel;public JTextField getjDel() if(jDel=null)jDel=new JTextField(20);
18、jDel.setBounds(100, 350, 150, 30);return jDel;public JButton getJbAdd() if(jbAdd=null)jbAdd=new JButton(添加);jbAdd.setBounds(100,400,60,30);return jbAdd;public JButton getJbSearch() if(jbSearch=null)jbSearch=new JButton(查找);jbSearch.setBounds(100, 450, 60, 30);return jbSearch;public JButton getJbUpda
19、te() if(jbUpdate=null)jbUpdate=new JButton(修改);jbUpdate.setBounds(180, 450, 60, 30);return jbUpdate;public JTable getTable() if(table=null)table=new JTable(100,6);table.setBounds(270, 50, 500, 600);return table;public JLabel getLblId() if(lblId=null)lblId=new JLabel(編號(hào));lblId.setBounds(50, 50, 50, 3
20、0);return lblId;public JLabel getLblBname() if(lblBname=null)lblBname=new JLabel(書名);lblBname.setBounds(50, 100, 50, 30);return lblBname;public JLabel getLblWname() if(lblWname=null)lblWname=new JLabel(作者);lblWname.setBounds(50,150, 50, 30);return lblWname;public JLabel getLblnum1() if(lblnum1=null)
21、lblnum1=new JLabel(現(xiàn)存量);lblnum1.setBounds(50,200, 50, 30);return lblnum1;public JLabel getLblnum2() if(lblnum2=null)lblnum2=new JLabel(庫(kù)存量);lblnum2.setBounds(50,250, 50, 30);return lblnum2;public JTextField getbId() if(bId=null)bId=new JTextField(20);bId.setBounds(100, 50,150, 30);return bId;public
22、JTextField getBname() if(bname=null)bname=new JTextField(20);bname.setBounds(100, 100, 150, 30);return bname;public JTextField getWname() if(wname=null)wname=new JTextField(20);wname.setBounds(100, 150, 150, 30);return wname;public JTextField getNum1() if(num1=null)num1=new JTextField(20);num1.setBo
23、unds(100, 200, 150, 30);return num1;public JTextField getNum2() if(num2=null)num2=new JTextField(20);num2.setBounds(100, 250, 150, 30);return num2;public JLabel getLblCbs() if(lblCbs=null)lblCbs=new JLabel(出版社);lblCbs.setBounds(50,300, 50, 30);return lblCbs;public JTextField getCbs() if(cbs=null)cbs
24、=new JTextField(20);cbs.setBounds(100, 300, 150, 30);return cbs;public Book(String title)super(title);/JFrame frame=new JFrame();Container cantainer=this.getContentPane();this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);ImageIcon img = new ImageIcon(F:Java傳習(xí)srcLibraryd50735fae6cd7b8961e8eafd0f244
25、2a7d8330ecc1.jpg);/這是背景圖片JLabel imgLabel = new JLabel(img);/將背景圖放在標(biāo)簽里。this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE);/注意這里是關(guān)鍵,將背景標(biāo)簽添加到j(luò)fram的LayeredPane面板里。imgLabel.setBounds(0,0,img.getIconWidth(), img.getIconHeight();/設(shè)置背景標(biāo)簽的位置cantainer.setLayout(new BorderLayout();imgLabel.setL
26、ayout(null);imgLabel.add(getLblId();imgLabel.add(getbId();imgLabel.add(getLblBname();imgLabel.add(getBname();imgLabel.add(getLblWname();imgLabel.add(getWname();imgLabel.add(getLblnum1();imgLabel.add(getNum1();imgLabel.add(getLblnum2();imgLabel.add(getNum2();imgLabel.add(getLblCbs();imgLabel.add(getC
27、bs();imgLabel.add(getTable();imgLabel.add(getJbDel();imgLabel.add(getjDel();imgLabel.add(getJbAdd();imgLabel.add(getJbSearch();imgLabel.add(getJbUpdate();imgLabel.add(getJabel();cantainer.add(imgLabel,BorderLayout.NORTH);(JPanel)cantainer).setOpaque(false); /注意這里,將內(nèi)容面板設(shè)為透明。這樣LayeredPane面板中的背景才能顯示出來(lái)。
28、this.setSize(img.getIconWidth(),img.getIconHeight();myEvent();this.setVisible(true);this.setResizable(true);private void myEvent() / TODO Auto-generated method stubjbAdd.addActionListener(new ActionListener()public void actionPerformed(ActionEvent ee)Connection conn=null;Statement stm=null;String id
29、1=bId.getText();String name1=bname.getText();String name2=wname.getText();String n1=num1.getText();String n2=num2.getText();String chubs=cbs.getText();tryClass.forName(com.mysql.jdbc.Driver);conn=DriverManager.getConnection(jdbc:mysql:/localhost:3306/library,sa,123456);stm=conn.createStatement();Str
30、ing sql=insert into book values(+id1+,+name1+,+name2+,+n1+,+n2+,+chubs+);stm.executeUpdate(sql);getbId().setText();getBname().setText();getWname().setText();getNum1().setText();getNum2().setText();getCbs().setText();catch(ClassNotFoundException e) catch (SQLException e) / TODO Auto-generated catch b
31、locke.printStackTrace();finally / 關(guān)閉Statement try stm.close(); catch (Exception e) / 關(guān)閉Connection try conn.close(); catch (Exception e) );jbDel.addActionListener(new ActionListener()public void actionPerformed(ActionEvent ee)String id=jDel.getText();Connection conn=null;Statement stm=null;tryClass.f
32、orName(com.mysql.jdbc.Driver);conn=DriverManager.getConnection(jdbc:mysql:/localhost:3306/library,sa,123456);/String sql=select * from book;String sql=delete from book where Bid=+id+;stm=conn.createStatement();stm.executeUpdate(sql);getjDel().setText();catch(ClassNotFoundException e) catch (SQLExcep
33、tion e) / TODO Auto-generated catch blocke.printStackTrace();finally / 關(guān)閉Statement try stm.close(); catch (Exception e) / 關(guān)閉Connection try conn.close(); catch (Exception e) );jbSearch.addActionListener(new ActionListener()public void actionPerformed(ActionEvent ee)String id=jDel.getText();Connection
34、 conn=null;Statement stm=null;ResultSet rst=null;tryClass.forName(com.mysql.jdbc.Driver);conn=DriverManager.getConnection(jdbc:mysql:/localhost:3306/library,sa,123456);/String sql=select * from book;String sql=select * from book where Bid=+id+;stm=conn.createStatement();rst=stm.executeQuery(sql);if(rst.next()getbId().setText(rst.getString(Bid);getBname().setText(rst.getString(Bname);getWname().setText(rst.getString(Wname);getNum1().setT
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024-2025學(xué)年高中語(yǔ)文課時(shí)作業(yè)12我有一個(gè)夢(mèng)想含解析新人教版必修21
- “國(guó)際文化貿(mào)易供應(yīng)鏈優(yōu)化”文化貿(mào)易供應(yīng)鏈優(yōu)化商業(yè)計(jì)劃書
- 帶帽直通行業(yè)深度研究報(bào)告
- 2025年錦綸纖維差別絲項(xiàng)目可行性研究報(bào)告
- 工業(yè)固體廢物資源綜合利用第三方企業(yè)申請(qǐng)報(bào)告模板
- 2025年電閘箱項(xiàng)目投資可行性研究分析報(bào)告-20241226-203622
- 2025年中國(guó)網(wǎng)絡(luò)機(jī)頂盒市場(chǎng)行情動(dòng)態(tài)分析及發(fā)展前景趨勢(shì)預(yù)測(cè)報(bào)告
- 2025年刺晶座行業(yè)深度研究分析報(bào)告
- 中國(guó)積放懸掛輸送機(jī)項(xiàng)目投資可行性研究報(bào)告
- 2023-2029年中國(guó)水路貨運(yùn)行業(yè)發(fā)展監(jiān)測(cè)及投資前景展望報(bào)告
- 第十八屆“地球小博士”全國(guó)地理知識(shí)科普競(jìng)賽題庫(kù)(附答案)
- 第13課《 擴(kuò)音系統(tǒng)的控制》說(shuō)課稿 2023-2024學(xué)年 浙教版六年級(jí)下冊(cè)信息科技
- 高校國(guó)有資產(chǎn)管理的三個(gè)維度與內(nèi)部控制
- 2025甘肅省事業(yè)單位聯(lián)考招聘(3141人)高頻重點(diǎn)提升(共500題)附帶答案詳解
- JJF 1176-2024(0~2 300) ℃鎢錸熱電偶校準(zhǔn)規(guī)范
- 8.4+同一直線上二力的合成課件+2024-2025學(xué)年人教版物理八年級(jí)下冊(cè)
- 2024年河北省邢臺(tái)市公開招聘警務(wù)輔助人員(輔警)筆試專項(xiàng)訓(xùn)練題試卷(2)含答案
- 家政公司服務(wù)員考試題庫(kù)單選題100道及答案解析
- 人工智能:AIGC基礎(chǔ)與應(yīng)用 課件 實(shí)訓(xùn)項(xiàng)目九 使用度加創(chuàng)作工具和剪映進(jìn)行智能化短視頻創(chuàng)作
- 《日影的朝向及長(zhǎng)短》課件
- 中職普通話教師教案模板
評(píng)論
0/150
提交評(píng)論