Java和SQL-Server2000開發(fā)的職工和工資管理系統(tǒng)(全過程與代碼)_第1頁
Java和SQL-Server2000開發(fā)的職工和工資管理系統(tǒng)(全過程與代碼)_第2頁
Java和SQL-Server2000開發(fā)的職工和工資管理系統(tǒng)(全過程與代碼)_第3頁
Java和SQL-Server2000開發(fā)的職工和工資管理系統(tǒng)(全過程與代碼)_第4頁
Java和SQL-Server2000開發(fā)的職工和工資管理系統(tǒng)(全過程與代碼)_第5頁
已閱讀5頁,還剩21頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

..工資管理系統(tǒng)一,設(shè)計數(shù)據(jù)庫SalaryManagement職工表:工資表二,創(chuàng)建"數(shù)據(jù)源<ODBC>"具體步驟:"開始"-"控制面板"-"管理工具"-"數(shù)據(jù)源<ODBC>-在用戶DNS里,點"添加"--在數(shù)據(jù)源驅(qū)動列表最下方選擇"SQLServer"-點"完成"--出現(xiàn)了一個創(chuàng)建到SQLServer的新數(shù)據(jù)源-在數(shù)據(jù)源"名稱"右側(cè),填寫數(shù)據(jù)庫的名稱;在"服務(wù)器"右側(cè),寫<local>-點"下一步"--繼續(xù)點"下一步"-在更改默認(rèn)的數(shù)據(jù)庫為"SalaryManagement",這里的數(shù)據(jù)庫為我剛剛新建的數(shù)據(jù)庫。-點"下一步"-點"完成"-出現(xiàn)一個"ODBCMicrosoftSQLServer安裝"對話框-點擊下面的"測試數(shù)據(jù)源"-出現(xiàn)圖2.1就好了。圖2.1-下面依次點擊"確定"就完成了。-完成了以后,你會在數(shù)據(jù)源里看到自己剛剛新建的數(shù)據(jù)源,名為:"SalaryManagement"三代碼的編寫:3.1數(shù)據(jù)庫連接〔文件名:DBConnect.java注意,這個文件最好先編譯,因為后面的main.java文件的編譯會用到該文件編譯完產(chǎn)生的DBConnect.class文件//類DBConnect用于數(shù)據(jù)庫的連接//導(dǎo)入sql包importjava.sql.*;//創(chuàng)建數(shù)據(jù)庫連接類DBConnectpublicclassDBConnect{ //靜態(tài)方法提高數(shù)據(jù)庫的連接效率 publicstaticConnectiongetConn<>throwsException { //加載JDBC驅(qū)動 Class.forName<"sun.jdbc.odbc.JdbcOdbcDriver">; //以系統(tǒng)默認(rèn)用戶身份,連接數(shù)據(jù)庫StudentManager returnDriverManager.getConnection<"jdbc:odbc:SalaryManagement","","">; }}3.2添加職工信息〔文件名:AddEmployee.java//添加職工面板類AddEmployee//導(dǎo)入系統(tǒng)的類包importjava.awt.*;importjava.sql.*;importjavax.swing.*;ent.*;//創(chuàng)建"添加職工"面板類publicclassAddEmployeeextendsJPanelimplementsActionListener{ //聲明連接數(shù)據(jù)庫對象 Connectioncon; //聲明SQL語句對象 Statementst; //創(chuàng)建組件對象:標(biāo)簽、文本行、單選 JLabeljLabel1=newJLabel<"職工工號">; JLabeljLabel2=newJLabel<"職工姓名">; JLabeljLabel3=newJLabel<"職工性別">; JLabeljLabel4=newJLabel<"職工年齡">; JLabeljLabel5=newJLabel<"家庭住址">; JLabeljLabel6=newJLabel<"">; JTextFieldjTextField1=newJTextField<>; JTextFieldjTextField2=newJTextField<>; JTextFieldjTextField3=newJTextField<>; JTextFieldjTextField4=newJTextField<>; JTextFieldjTextField5=newJTextField<>; JRadioButtonjRadioButton1=newJRadioButton<"男">; JRadioButtonjRadioButton2=newJRadioButton<"女">; ButtonGroupbuttonGroup1=newButtonGroup<>; uttonutton1=newutton<"添加職工">; //構(gòu)造方法 publicAddEmployee<> { try{ //調(diào)用初始化方法 Init<>; } catch<Exceptionexception>{ exception.printStackTrace<>; } } //界面初始化方法 privatevoidInit<>throwsException { //連接數(shù)據(jù)庫 con=DBConnect.getConn<>; st=con.createStatement<>; //框架的布局 this.setLayout<null>; //設(shè)置各組件的大小 jLabel1.setBounds<newRectangle<21,17,64,24>>; jLabel2.setBounds<newRectangle<21,51,53,22>>; jLabel3.setBounds<newRectangle<21,86,61,27>>; jLabel4.setBounds<newRectangle<21,122,59,25>>; jLabel5.setBounds<newRectangle<21,168,54,24>>; jLabel6.setBounds<newRectangle<21,205,54,24>>; jTextField1.setBounds<newRectangle<102,10,200,30>>; jTextField2.setBounds<newRectangle<102,49,200,30>>; jTextField3.setBounds<newRectangle<102,117,80,33>>; jTextField4.setBounds<newRectangle<102,163,200,29>>; jTextField5.setBounds<newRectangle<102,200,200,29>>; jRadioButton1.setBounds<newRectangle<102,83,65,30>>; jRadioButton2.setBounds<newRectangle<190,85,85,30>>; utton1.setBounds<newRectangle<130,240,150,32>>; //設(shè)置單選按鈕被選中 jRadioButton1.setSelected<true>; //添加按鈕動作事件 utton1.addActionListener<this>; //添加組件到面板 this.add<jLabel1>; this.add<jTextField1>; this.add<jLabel2>; this.add<jTextField2>; this.add<jLabel3>; buttonGroup1.add<jRadioButton1>; buttonGroup1.add<jRadioButton2>; this.add<jRadioButton1>; this.add<jRadioButton2>; this.add<jLabel4>; this.add<jTextField3>; this.add<jLabel5>; this.add<jTextField4>; this.add<jLabel6>; this.add<jTextField5>; this.add<utton1>; } //點擊按鈕事件 publicvoidactionPerformed<ActionEvente> { //獲取用戶輸入的信息 StringEmployeeID=jTextField1.getText<>; StringEmployeeName=jTextField2.getText<>; StringEmployeeSex=""; if<jRadioButton1.isSelected<>> EmployeeSex+="男"; if<jRadioButton2.isSelected<>> EmployeeSex+="女"; StringEmployeeAge=jTextField3.getText<>; StringEmployeeAddress=jTextField4.getText<>; StringEmployeePhone=jTextField5.getText<>; try{ //設(shè)置日期格式 st.execute<"setdateformatymd">; //利用st對象執(zhí)行SQL語句,進(jìn)行插入操作 st.executeUpdate<"insertintoEmployeevalues<'"+EmployeeID+"','"+EmployeeName+"','"+EmployeeSex+"','"+EmployeeAge+"','"+EmployeeAddress+"','"+EmployeePhone+"'>">; //利用消息對話框提示職工添加成功 JOptionPane.showMessageDialog<this,"職工添加成功!">; //清空文本行的內(nèi)容 jTextField1.setText<"">; jTextField2.setText<"">; jTextField3.setText<"">; jTextField4.setText<"">; jTextField5.setText<"">; } catch<Exceptionex>{ //利用消息對話框提示異常的信息 JOptionPane.showMessageDialog<this,"職工添加失敗!">; ex.printStackTrace<>; } }}3.3修改職工信息〔文件名:ModifyEmployee.java//"職工信息修改"面板類ModifyEmployee//導(dǎo)入系統(tǒng)的類包importjava.awt.*;importjava.sql.*;importjavax.swing.*;importjava.awt.event.*;//創(chuàng)建"職工信息修改資"類publicclassModifyEmployeeextendsJPanelimplementsActionListener{ //聲明連接數(shù)據(jù)庫對象 Connectioncon; //聲明SQL語句對象 Statementst; //創(chuàng)建組件對象:標(biāo)簽、文本行、單選 JLabeljLabel1=newJLabel<"請輸入職工的編號:">; JTextFieldjTextField1=newJTextField<>; uttonutton1=newutton<"查找該職工">; JLabeljLabel2=newJLabel<"職工編號:">; JTextFieldjTextField2=newJTextField<>; JLabeljLabel3=newJLabel<"職工姓名:">; JTextFieldjTextField3=newJTextField<>; JLabeljLabel4=newJLabel<"職工性別:">; JTextFieldjTextField4=newJTextField<>; JLabeljLabel5=newJLabel<"職工年齡:">; JTextFieldjTextField5=newJTextField<>; JLabeljLabel6=newJLabel<"家庭住址:">; JTextFieldjTextField6=newJTextField<>; JLabeljLabel7=newJLabel<":">; JTextFieldjTextField7=newJTextField<>; uttonutton2=newutton<"修改職工信息">; //構(gòu)造方法 publicModifyEmployee<> { try{ //調(diào)用初始化方法 Init<>; } catch<Exceptionexception>{ exception.printStackTrace<>; } } //面板初始化方法 privatevoidInit<>throwsException { //連接數(shù)據(jù)庫 con=DBConnect.getConn<>; st=con.createStatement<>; //框架的布局 this.setLayout<null>; //設(shè)置各組件的大小 jLabel1.setFont<newjava.awt.Font<"楷體",Font.BOLD,14>>; jLabel1.setBounds<newRectangle<40,15,140,30>>; jTextField1.setBounds<newRectangle<185,15,120,30>>; utton1.setBounds<newRectangle<110,55,150,30>>; jLabel2.setFont<newjava.awt.Font<"楷體",Font.BOLD,14>>; jLabel2.setBounds<newRectangle<20,105,80,30>>; jTextField2.setBounds<newRectangle<100,105,80,30>>; jLabel3.setFont<newjava.awt.Font<"楷體",Font.BOLD,14>>; jLabel3.setBounds<newRectangle<190,105,80,30>>; jTextField3.setBounds<newRectangle<270,105,80,30>>; jLabel4.setFont<newjava.awt.Font<"楷體",Font.BOLD,14>>; jLabel4.setBounds<newRectangle<20,145,80,30>>; jTextField4.setBounds<newRectangle<100,145,80,30>>; jLabel5.setFont<newjava.awt.Font<"楷體",Font.BOLD,14>>; jLabel5.setBounds<newRectangle<190,145,80,30>>; jTextField5.setBounds<newRectangle<270,145,80,30>>; jLabel6.setFont<newjava.awt.Font<"楷體",Font.BOLD,14>>; jLabel6.setBounds<newRectangle<20,185,80,30>>; jTextField6.setBounds<newRectangle<100,185,80,30>>; jLabel7.setFont<newjava.awt.Font<"楷體",Font.BOLD,14>>; jLabel7.setBounds<newRectangle<190,185,80,30>>; jTextField7.setBounds<newRectangle<270,185,80,30>>; utton2.setBounds<newRectangle<120,240,150,30>>; //添加按鈕動作事件 utton1.addActionListener<this>; utton2.addActionListener<this>; //添加組件到面板 this.add<jLabel1>; this.add<jTextField1>; this.add<utton1>; this.add<jLabel2>; this.add<jTextField2>; jTextField2.setEditable<false>; this.add<jLabel3>; this.add<jTextField3>; this.add<jLabel4>; this.add<jTextField4>; this.add<jLabel5>; this.add<jTextField5>; this.add<jLabel6>; this.add<jTextField6>; this.add<jLabel7>; this.add<jTextField7>; this.add<utton2>; } //點擊按鈕事件 publicvoidactionPerformed<ActionEventactionevent> { //點擊"查找該職工"按鈕 if<actionevent.getSource<>==utton1> { try{ //利用st對象執(zhí)行SQL語句,返回結(jié)果集對象 ResultSetrs=st.executeQuery<"select*fromEmployeewhere職工編號='"+jTextField1.getText<>+"'">; //處理結(jié)果集 if<rs.next<>> { jTextField2.setText<rs.getString<"職工編號">>; jTextField3.setText<rs.getString<"職工姓名">>; jTextField4.setText<rs.getString<"職工性別">>; jTextField5.setText<rs.getString<"職工年齡">>; jTextField6.setText<rs.getString<"家庭住址">>; jTextField7.setText<rs.getString<"">>; } else { JOptionPane.showMessageDialog<this,"沒有這個工號的職工!">; } } catch<Exceptionex>{ //利用消息對話框提示查詢失敗 JOptionPane.showMessageDialog<this,"職工信息修改失敗!">; } } //點擊"修改工資"按鈕 if<actionevent.getSource<>==utton2> { //獲取用戶更改的工資 try{ //利用st對象執(zhí)行SQL語句,進(jìn)行插入操作 st.executeUpdate<"updateEmployeeset職工姓名='"+jTextField3.getText<>+"'where職工編號='"+jTextField2.getText<>+"'">; st.executeUpdate<"updateEmployeeset職工性別='"+jTextField4.getText<>+"'where職工編號='"+jTextField2.getText<>+"'">; st.executeUpdate<"updateEmployeeset職工年齡='"+jTextField5.getText<>+"'where職工編號='"+jTextField2.getText<>+"'">; st.executeUpdate<"updateEmployeeset家庭住址='"+jTextField6.getText<>+"'where職工編號='"+jTextField2.getText<>+"'">; st.executeUpdate<"updateEmployeeset='"+jTextField7.getText<>+"'where職工編號='"+jTextField2.getText<>+"'">; //利用消息對話框提示職工信息修改成功 JOptionPane.showMessageDialog<this,"職工信息修改成功!">; } catch<Exceptionex>{ //利用消息對話框提示異常的信息 JOptionPane.showMessageDialog<this,"職工信息修改失?。?>; ex.printStackTrace<>; } } }}3.4刪除職工信息〔文件名:DeleteEmployee.java//"刪除職工"面板類DeleteEmployee//導(dǎo)入系統(tǒng)的類包importjava.awt.*;importjava.sql.*;importjavax.swing.*;importjava.awt.event.*;//創(chuàng)建"刪除職工"類publicclassDeleteEmployeeextendsJPanelimplementsActionListener{ //聲明連接數(shù)據(jù)庫對象 Connectioncon; //聲明SQL語句對象 Statementst; //創(chuàng)建組件對象 JLabeljLabel1=newJLabel<"請輸入待刪除的職工的編號">; JTextFieldjTextField1=newJTextField<>; uttonutton1=newutton<"刪除">; //構(gòu)造方法 publicDeleteEmployee<> { try{ //調(diào)用初始化方法 Init<>; } catch<Exceptionexception>{ exception.printStackTrace<>; } } //界面初始化方法 privatevoidInit<>throwsException { //連接數(shù)據(jù)庫 con=DBConnect.getConn<>; st=con.createStatement<>; //框架的布局 this.setLayout<null>; //設(shè)置各組件的大小 jLabel1.setFont<newjava.awt.Font<"黑體",Font.BOLD,14>>; jLabel1.setBounds<newRectangle<70,20,200,30>>; jTextField1.setBounds<newRectangle<70,80,207,41>>; utton1.setBounds<newRectangle<70,175,205,36>>; //添加按鈕動作事件 utton1.addActionListener<this>; //添加組件到面板 this.add<jLabel1>; this.add<jTextField1>; this.add<utton1>; } //點擊按鈕事件 publicvoidactionPerformed<ActionEvente> { //獲取用戶輸入的職工編號 StringEmployeeID=jTextField1.getText<>; //要求用戶確認(rèn)刪除 if<JOptionPane.showConfirmDialog<this,"確認(rèn)要刪除嗎?">==JOptionPane.YES_OPTION> { try{ //利用st對象執(zhí)行SQL刪除操作 st.executeUpdate<"deletefromEmployeewhere職工編號='"+EmployeeID+"'">; //利用消息對話框提示刪除操作成功 JOptionPane.showMessageDialog<this,"職工刪除操作,執(zhí)行成功!">; //清空輸入學(xué)號的文本行 jTextField1.setText<"">; } catch<Exceptionex>{ //利用消息對話框提示不能刪除 JOptionPane.showMessageDialog<this,"職工刪除操作,執(zhí)行失敗!">; } } }}3.5添加工資類〔文件名:AddSalary.java//"添加工資"面板類AddSalary//導(dǎo)入系統(tǒng)的類包importjava.awt.*;importjava.sql.*;importjavax.swing.*;importjava.awt.event.*;//創(chuàng)建"添加工資"類publicclassAddSalaryextendsJPanelimplementsActionListener{ //聲明連接數(shù)據(jù)庫對象 Connectioncon; //聲明SQL語句對象 Statementst; //創(chuàng)建組件對象:標(biāo)簽、文本行、單選 JLabeljLabel1=newJLabel<"職工工號">; JLabeljLabel2=newJLabel<"職工工資">; JTextFieldjTextField1=newJTextField<>; JTextFieldjTextField2=newJTextField<>; uttonutton1=newutton<"添加工資">; //構(gòu)造方法 publicAddSalary<> { try{ //調(diào)用初始化方法 Init<>; } catch<Exceptionexception>{ exception.printStackTrace<>; } } //界面初始化方法 privatevoidInit<>throwsException { //連接數(shù)據(jù)庫 con=DBConnect.getConn<>; st=con.createStatement<>; //框架的布局 this.setLayout<null>; //設(shè)置各組件的大小 jLabel1.setBounds<newRectangle<21,17,64,24>>; jLabel2.setBounds<newRectangle<21,51,53,22>>; jTextField1.setBounds<newRectangle<102,10,200,30>>; jTextField2.setBounds<newRectangle<102,60,200,30>>; utton1.setBounds<newRectangle<130,120,150,32>>; //添加按鈕動作事件 utton1.addActionListener<this>; //添加組件到面板 this.add<jLabel1>; this.add<jTextField1>; this.add<jLabel2>; this.add<jTextField2>; this.add<utton1>; } //點擊按鈕事件 publicvoidactionPerformed<ActionEvente> { //獲取用戶輸入的信息 StringEmployeeID=jTextField1.getText<>; StringEmployeeSalary=jTextField2.getText<>; try{ //利用st對象執(zhí)行SQL語句,進(jìn)行插入操作 st.executeUpdate<"insertintoSalaryvalues<'"+EmployeeID+"','"+EmployeeSalary+"'>">; //利用消息對話框提示工資添加成功 JOptionPane.showMessageDialog<this,"工資添加成功!">; //清空文本行的內(nèi)容 jTextField1.setText<"">; jTextField2.setText<"">; } catch<Exceptionex>{ //利用消息對話框提示異常的信息 JOptionPane.showMessageDialog<this,"工資添加失?。?>; ex.printStackTrace<>; } }}3.6修改工資信息〔文件名ModifySalary.java//"修改工資"面板類ModifySalary//導(dǎo)入系統(tǒng)的類包importjava.awt.*;importjava.sql.*;importjavax.swing.*;importjava.awt.event.*;//創(chuàng)建"修改工資"面板類publicclassModifySalaryextendsJPanelimplementsActionListener{ //聲明連接數(shù)據(jù)庫對象 Connectioncon; //聲明SQL語句對象 Statementst; //創(chuàng)建組件對象:標(biāo)簽、文本行、單選 JLabeljLabel1=newJLabel<"請輸入職工的編號:">; JTextFieldjTextField1=newJTextField<>; uttonutton1=newutton<"查找該職工">; JLabeljLabel2=newJLabel<"職工編號:">; JTextFieldjTextField2=newJTextField<>; JLabeljLabel3=newJLabel<"職工工資:">; JTextFieldjTextField3=newJTextField<>; uttonutton2=newutton<"修改工資">; //構(gòu)造方法 publicModifySalary<> { try{ //調(diào)用初始化方法 Init<>; } catch<Exceptionexception>{ exception.printStackTrace<>; } } //面板初始化方法 privatevoidInit<>throwsException { //連接數(shù)據(jù)庫 con=DBConnect.getConn<>; st=con.createStatement<>; //框架的布局 this.setLayout<null>; //設(shè)置各組件的大小 jLabel1.setFont<newjava.awt.Font<"楷體",Font.BOLD,14>>; jLabel1.setBounds<newRectangle<40,25,140,30>>; jTextField1.setBounds<newRectangle<185,25,120,30>>; utton1.setBounds<newRectangle<110,65,120,30>>; jLabel2.setFont<newjava.awt.Font<"楷體",Font.BOLD,14>>; jLabel2.setBounds<newRectangle<90,125,80,30>>; jTextField2.setBounds<newRectangle<170,125,80,30>>; jLabel3.setFont<newjava.awt.Font<"楷體",Font.BOLD,14>>; jLabel3.setBounds<newRectangle<90,160,80,30>>; jTextField3.setBounds<newRectangle<170,160,80,30>>; utton2.setBounds<newRectangle<120,200,100,30>>; //添加按鈕動作事件 utton1.addActionListener<this>; utton2.addActionListener<this>; //添加組件到面板 this.add<jLabel1>; this.add<jTextField1>; this.add<utton1>; this.add<jLabel2>; this.add<jTextField2>; jTextField2.setEditable<false>; this.add<jLabel3>; this.add<jTextField3>; this.add<utton2>; } //點擊按鈕事件 publicvoidactionPerformed<ActionEventactionevent> { //點擊"查找該職工"按鈕 if<actionevent.getSource<>==utton1> { //獲取輸入的職工的編號 StringEmployeeID=jTextField1.getText<>; try{ //利用st對象執(zhí)行SQL語句,返回結(jié)果集對象 ResultSetrs=st.executeQuery<"select*fromSalarywhere職工編號='"+EmployeeID+"'">; //處理結(jié)果集 if<rs.next<>> { jTextField2.setText<rs.getString<"職工編號">>; jTextField3.setText<rs.getString<"職工工資">>; } else { JOptionPane.showMessageDialog<this,"沒有這個工號的職工!">; } } catch<Exceptionex>{ //利用消息對話框提示查詢失敗 JOptionPane.showMessageDialog<this,"工資修改失敗!">; } } //點擊"修改工資"按鈕 if<actionevent.getSource<>==utton2> { //獲取用戶更改的工資 try{ //利用st對象執(zhí)行SQL語句,進(jìn)行修改操作 st.executeUpdate<"updateSalaryset職工工資='"+jTextField3.getText<>+"'where職工編號='"+jTextField2.getText<>+"'">; //利用消息對話框提示工資修改成功 JOptionPane.showMessageDialog<this,"工資修改成功!">; } catch<Exceptionex>{ //利用消息對話框提示異常的信息 JOptionPane.showMessageDialog<this,"工資修改失敗!">; ex.printStackTrace<>; } } }}3.7查詢工資〔文件名SalaryInquire.java//"工資查詢"面板類SalaryInquire//導(dǎo)入系統(tǒng)的類包importjava.awt.*;importjava.sql.*;importjavax.swing.*;importjava.awt.event.*;//創(chuàng)建"工資查詢"類publicclassSalaryInquireextendsJPanelimplementsActionListener{ //聲明連接數(shù)據(jù)庫對象 Connectioncon; //聲明SQL語句對象 Statementst; //創(chuàng)建組件對象:標(biāo)簽、文本行、單選 JLabeljLabel1=newJLabel<"請輸入要查詢的職工的編號:">; JTextFieldjTextField1=newJTextField<>; uttonutton1=newutton<"工資查詢">; JTextAreajTextArea1=newJTextArea<>; //構(gòu)造方法 publicSalaryInquire<> { try{ //調(diào)用初始化方法 Init<>; } catch<Exceptionexception>{ exception.printStackTrace<>; } } //面板初始化方法 privatevoidInit<>throwsException { //連接數(shù)據(jù)庫 con=DBConnect.getConn<>; st=con.createStatement<>; //框架的布局 this.setLayout<null>; //設(shè)置各組件的大小 jLabel1.setFont<newjava.awt.Font<"黑體",Font.BOLD,16>>; jLabel1.setBounds<newRectangle<46,4,222,32>>; jTextField1.setBounds<newRectangle<47,37,247,31>>; utton1.setBounds<newRectangle<47,86,247,30>>; jTextArea1.setBounds<newRectangle<24,130,305,109>>; //添加按鈕動作事件 utton1.addActionListener<this>; //添加組件到面板 this.add<jLabel1>; this.add<jTextField1>; this.add<jTextArea1>; this.add<utton1>; } //點擊按鈕事件 publicvoidactionPerformed<ActionEvente> { //獲取輸入的職工的編號 StringEmployeeID=jTextField1.getText<>; //清空文本區(qū)原有的內(nèi)容 jTextArea1.setText<"">; try{ //利用st對象執(zhí)行SQL語句,返回結(jié)果集對象 ResultSetrs=st.executeQuery<"select*fromSalarywhere職工編號='"+EmployeeID+"'">; //處理結(jié)果集 if<rs.next<>> { jTextArea1.setText<"職工編號:"+rs.getString<"職工編號">+"\n"+"職工工資:"+rs.getString<"職工工資">+"\n">; } else { JOptionPane.showMessageDialog<this,"該工號的職工沒有工資記錄!">; } } catch<Exceptionex>{ //利用消息對話框提示查詢失敗 JOptionPane.showMessageDialog<this,"工資查詢失敗!">; } }}3.8按編號查詢程序〔文件名InquireOnGH.java//"按職工的編號查詢"面板類InquireOnGH//導(dǎo)入系統(tǒng)的類包importjava.awt.*;importjava.sql.*;importjavax.swing.*;importjava.awt.event.*;//創(chuàng)建"按職工的編號查詢"類publicclassInquireOnGHextendsJPanelimplementsActionListener{ //聲明連接數(shù)據(jù)庫對象 Connectioncon; //聲明SQL語句對象 Statementst; //創(chuàng)建組件對象:標(biāo)簽、文本行、單選 JLabeljLabel1=newJLabel<"請輸入職工的編號:">; JTextFieldjTextField1=newJTextField<>; uttonutton1=newutton<"查找">; JTextAreajTextArea1=newJTextArea<>; //構(gòu)造方法 publicInquireOnGH<> { try{ //調(diào)用初始化方法 Init<>; } catch<Exceptionexception>{ exception.printStackTrace<>; } } //面板初始化方法 privatevoidInit<>throwsException { //連接數(shù)據(jù)庫 con=DBConnect.getConn<>; st=con.createStatement<>; //框架的布局 this.setLayout<null>; //設(shè)置各組件的大小 jLabel1.setFont<newjava.awt.Font<"黑體",Font.BOLD,16>>; jLabel1.setBounds<newRectangle<46,4,222,32>>; jTextField1.setBounds<newRectangle<47,37,247,31>>; utton1.setBounds<newRectangle<47,86,247,30>>; jTextArea1.setBounds<newRectangle<24,130,305,109>>; //添加按鈕動作事件 utton1.addActionListener<this>; //添加組件到面板 this.add<jLabel1>; this.add<jTextField1>; this.add<jTextArea1>; this.add<utton1>; } //點擊按鈕事件 publicvoidactionPerformed<ActionEvente> { //獲取輸入的職工的編號 StringEmployeeID=jTextField1.getText<>; //清空文本區(qū)原有的內(nèi)容 jTextArea1.setText<"">; try{ //利用st對象執(zhí)行SQL語句,返回結(jié)果集對象 ResultSetrs=st.executeQuery<"select*fromEmployeewhere職工編號='"+EmployeeID+"'">; //處理結(jié)果集 if<rs.next<>> { jTextArea1.setText<"職工編號:"+rs.getString<"職工編號">+"\n"+"職工姓名:"+rs.getString<"職工姓名">+"\n"+"職工性別:"+rs.getString<"職工性別">+"\n"+"職工年齡:"+rs.getString<"職工年齡">+"\n"+"家庭住址:"+rs.getString<"家庭住址">+"\n"+":"+rs.getString<"">+"\n">; } else { JOptionPane.showMessageDialog<this,"沒有這個工號的職工!">; } } catch<Exceptionex>{ //利用消息對話框提示查詢失敗 JOptionPane.showMessageDialog<this,"職工查詢失敗!">; } }}3.9按姓名查詢程序〔文件名InquireOnName.java//"按職工的姓名查詢"面板類InquireOnName//導(dǎo)入系統(tǒng)的類包importjava.awt.*;importjava.sql.*;importjavax.swing.*;importjava.awt.event.*;//創(chuàng)建"按職工的姓名查詢"類publicclassInquireOnNameextendsJPanelimplementsActionListener{ //聲明連接數(shù)據(jù)庫對象 Connectioncon; //聲明SQL語句對象 Statementst; //創(chuàng)建組件對象:標(biāo)簽、文本行、單選 JLabeljLabel1=newJLabel<"請輸入職工的__">; JTextFieldjTextField1=newJTextField<>; uttonutton1=newutton<"查找">; JTextAreajTextArea1=newJTextArea<>; //構(gòu)造方法 publicInquireOnName<> { try{ //調(diào)用初始化方法 Init<>; } catch<Exceptionexception>{ exception.printStackTrace<>; } } //面板初始化方法 privatevoidInit<>throwsException { //連接數(shù)據(jù)庫 con=DBConnect.getConn<>; st=con.createStatement<>; //框架的布局 this.setLayout<null>; //設(shè)置各組件的大小 jLabel1.setFont<newjava.awt.Font<"黑體",Font.BOLD,16>>; jLabel1.setBounds<newRectangle<46,4,222,32>>; jTextField1.setBounds<newRectangle<47,37,247,31>>; utton1.setBounds<newRectangle<47,86,247,30>>; jTextArea1.setBounds<newRectangle<24,130,305,109>>; //添加按鈕動作事件 utton1.addActionListener<this>; //添加組件到面板 this.add<jLabel1>; this.add<jTextField1>; this.add<jTextArea1>; this.add<utton1>; } //點擊按鈕事件 publicvoidactionPerformed<ActionEvente> { //獲取輸入的職工的姓名 StringEmployeeName=jTextField1.getText<>; //清空文本區(qū)原有的內(nèi)容 jTextArea1.setText<"">; try{ //利用st對象執(zhí)行SQL語句,返回結(jié)果集對象 ResultSetrs=st.executeQuery<"select*fromEmployeewhere職工姓名='"+EmployeeName+"'">; //處理結(jié)果集 if<rs.next<>> { jTextArea1.setText<"職工編號:"+rs.getString<"職工編號">+"\n"+"職工姓名:"+rs.getString<"職工姓名">+"\n"+"職工性別:"+rs.getString<"職工性別">+"\n"+"職工年齡:"+rs.getString<"職工年齡">+"\n"+"家庭住址:"+rs.getString<"家庭住址">+"\n"+":"+rs.getString<"">+"\n">; } else { JOptionPane.showMessageDialog<this,"沒有這個工號的職工!">; } } catch<Exceptionex>{ //利用消息對話框提示查詢失敗 JOptionPane.showMessageDialog<this,"職工查詢失敗!">; } }}3.10按幫助查詢程序〔文件名EmployeeHelp.java//"幫助"面板類EmployeeHelp//導(dǎo)入系統(tǒng)的類包importjava.awt.*;importjava.sql.*;importjavax.swing.*;importjava.awt.event.*;//創(chuàng)建"幫助"面板類publicclassEmployeeHelpextendsJPanel{ //創(chuàng)建組件對象:標(biāo)簽 JLabeljLabel1=newJLabel<"有問題,請你聯(lián)系">; JLabeljLabel4=newJLabel<"林德軍">; JLabeljLabel2=newJLabel<"QQ:929156887">; JLabeljLabel3=newJLabel<"郵箱:929156887qq">; //構(gòu)造方法 publicEmployeeHelp<> { try{ //調(diào)用初始化方法 Init<>; } catch<Exceptionexception>{ exception.printStackTrace<>; } } //初始化 privatevoidInit<>throwsException { //框架的布局 this.setLayout<null>; //設(shè)置各組件的大小 jLabel1.setFont<newjava.awt.Font<"楷體",Font.BOLD,20>>; jLabel1.setBounds<newRectangle<50,50,300,30>>; jLabel4.setFont<newjava.awt.Font<"楷體",Font.BOLD,20>>; jLabel4.setBounds<newRectangle<50,90,150,30>>; jLabel2.setFont<newjava.awt.Font<"楷體",Font.BOLD,20>>; jLabel2.setBounds<newRectangle<50,140,300,30>>; jLabel3.setFont<newjava.awt.Font<"楷體",Font.BOLD,20>>; jLabel3.setBounds<newRectangle<50,180,300,30>>; //添加組件到面板 this.add<jLabel1>; this.add<jLabel2>; this.add<jLabel3>; this.add<jLabel4>; }}3.11主框架程序〔文件名MainFrame.java//系統(tǒng)主框架類//導(dǎo)入系統(tǒng)的包importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;//創(chuàng)建主框架類MainFramepublicclassMainFrameextendsJFrameimplementsActionListener{ //創(chuàng)建內(nèi)容面板 JPanelcontentPane; //創(chuàng)建菜單欄組件的對象 JMenuBarjMenuBar1=newJMenuBar<>;//菜單條 JMenujMenu0=newJMenu<"系統(tǒng)">;//菜單 JMenuItemjMenuItem0=newJMenuItem<"退出">;//子菜單 JMenujMenu1=newJMenu<"職工管理">; JMenuItemjMenuItem1=newJMenuItem<"添加職工">; JMenuItemjMenuItem2=newJMenuItem<"修改職工">; JMenuItemjMenuItem3=newJMenuItem<"刪除職工">; JMenujMenu2=newJMenu<"工資管理">; JMenuItemjMenuItem4=newJMenuItem<"添加工資">; JMenuItemjMenuItem5=newJMenuItem<"修改工資">; JMenuItemjMenuItem8=newJMenuItem<"工資查詢">; JMenujMenu3=newJMenu<"職工查詢">; JMenuItemjMenuItem6=newJMenuItem<"按工號查詢">; JMenuItemjMenuItem7=newJMenuItem<"按姓名查詢">; JMenujMenu4=newJMenu<"幫助">; JMenuItemjMenuItem9=newJMenuItem<"互動">; //創(chuàng)建標(biāo)簽,用于顯示信息 JLabeljLabel1=newJLabel<"職工和工資管理小系統(tǒng)">; JLabeljLabel2=newJLabel<"2010年12月22日,林德軍">; //創(chuàng)建構(gòu)造方法 publicMainFrame<> { try{ //關(guān)閉框架窗口時的默認(rèn)事件方法 setDefaultCloseOperation<EXIT_ON_CLOSE>; //調(diào)用初始化方法 Init<>; } catch<Exceptionexception>{ exception.printStackTrace<>; } } //界面初始化方法 privatevoidInit<>throwsException { //創(chuàng)建內(nèi)容面板 contentPane=<JPanel>getContentPane<>; //設(shè)置內(nèi)容面板的布局為空 contentPane.setLayout<null>; //主框架的大小 setSize<newDimension<400,360>>; //主框架的標(biāo)題 setTitle<"職工和工資管理小系統(tǒng)">; //添加事件監(jiān)聽器 jMenuItem0.addActionListener<this>; jMenuItem1.addActionListener<this>; jMenuItem2.addActionListener<this>; jMenuItem3.addActionListener<this>; jMenuItem4.addActionListener<this>; jMenuItem5.addActionListener<this>; jMenuItem6.addActionListener<this>; jMenuItem7.addActionListener<this>; jMenuItem8.addActionListener<this>; jMenuItem9.addActionListener<this>; //添加菜單條到主框架 setJMenuBar<jMenuBar1>; //添加菜單到菜單條 jMenuBar1.add<jMenu0>; jMenuBar1.add<jMenu1>; jMenuBar1.add<jMenu2>; jMenuBar1.add<jMenu3>; jMenuBar1.add<jMenu4>; //添加菜單項到菜單 jMenu0.add<jMenuItem0>; jMenu1.add<jMenuItem1>; jMenu1.add<jMenuItem2>; jMenu1.add<jMenuItem3>; jMenu2.add<jMenuItem4>; jMenu2.add<jMenuItem5>; jMenu2.add<jMenuItem8>; jMenu3.add<jMenuItem6>; jMenu3.add<jMenuItem7>; jMenu4.add<jMenuItem9>; //添加標(biāo)簽到主框架內(nèi)容面板 contentPane.add<jLabel1>; contentPane.add<jLabel2>; //設(shè)置標(biāo)簽組件的大小和字體 jLabel1.setFont<newjava.awt.Font<"黑體",Font.BOLD,20>>; jLabel1.setBounds<newRectangle<65,70,275,55>>; jLabel2.setFont<newjava.awt.Font<"黑體",Font.BOLD,16>>; jLabel2.setBounds<newRectangle<90,150,200,35>>; } //菜單項事件對應(yīng)的處理方法 publicvoidactionPerformed<ActionEventactionEvent> { //點擊"系統(tǒng)"菜單下的"退出"菜單項 if<actionEvent.getSource<>==jMenuItem0> { System.exit<0>; } //點擊"職工管理"菜單下的"添加職工"菜單項 if<actionEvent.getSource<>==jMenuItem1> { //創(chuàng)建"添加職工"面板對象 AddEmployeeAddEmp=newAddEmployee<>; //移除主框架上原有的內(nèi)容 this.remove<this.getContentPane<>>; //加載"添加職工"面板的對象到主框架 this.setContentPane<AddEmp>; //令界面可見 this.setVisible<true>; } //點擊"職工管理"菜單下的"修改職工"菜單項 if<actionEvent.getSource<>==jMenuItem2> { //創(chuàng)建"修改職工"面板對象 ModifyEmployeeModifyEmp=newModifyEmpl

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論