面向?qū)ο笳n程設(shè)計(jì)java大作業(yè)報(bào)告含源代碼_第1頁
面向?qū)ο笳n程設(shè)計(jì)java大作業(yè)報(bào)告含源代碼_第2頁
面向?qū)ο笳n程設(shè)計(jì)java大作業(yè)報(bào)告含源代碼_第3頁
面向?qū)ο笳n程設(shè)計(jì)java大作業(yè)報(bào)告含源代碼_第4頁
面向?qū)ο笳n程設(shè)計(jì)java大作業(yè)報(bào)告含源代碼_第5頁
已閱讀5頁,還剩16頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、Java 程序設(shè)計(jì)報(bào)告年級(jí)專業(yè) 信息管理與信息系統(tǒng)學(xué)號(hào)學(xué)生姓名指導(dǎo)教師二一四年六月、所用到的表的結(jié)構(gòu)及數(shù)據(jù)類型customer 顧客表表名customer 顧客說明此表記錄顧客基本信息列名說明數(shù)據(jù)類型約束cno顧客編號(hào)char(10)主碼cname顧客姓名char(10)cage年齡intcsex性別char(2)取值為男或女,默認(rèn)女ctelepho ne顧客聯(lián)系方式char(15)非空操作人員表表名操作人員說明此表記錄操作人員信息列名說明數(shù)據(jù)類型約束用戶名用戶登錄名nchar(10)主碼密碼登錄密碼nchar(3)非空職位擔(dān)任職務(wù)nchar(10)二、程序的功能及實(shí)現(xiàn)結(jié)果截圖1、 登錄功能打

2、開 Java 文件 Login.java 運(yùn)行后輸入錯(cuò)誤的用戶名后出現(xiàn):輸入用戶名 Lucy 密碼: 123 點(diǎn)擊登錄進(jìn)入操作界面:2、 添加功能 下拉顧客信息系統(tǒng)菜單,選擇添加客戶信息 添加信息前數(shù)據(jù)庫客戶表的內(nèi)容:沒有編號(hào) 0000013添加客戶 0000013:張薔, 29,女, 0000013,數(shù)據(jù)庫內(nèi)表變?yōu)椋鹤ⅲ?0000015 號(hào)是截圖之前添加進(jìn)去的3、 查詢功能 下拉客戶信息系統(tǒng)菜單, 選擇查詢客戶信息, 輸入客戶編碼 0000013 后點(diǎn)擊確定查 詢此顧客:4、修改功能下拉菜單客戶信息系統(tǒng), 選擇修改客戶信息, 重新輸入相應(yīng)的正確信息, 將錯(cuò)誤的 覆蓋

3、掉,此處將 0000013 張薔年齡改為 32:數(shù)據(jù)庫表內(nèi)內(nèi)容 :5、0000013 點(diǎn)擊確認(rèn):刪除功能下拉菜單客戶信息系統(tǒng),選擇刪除客戶信息,輸入客戶編碼數(shù)據(jù)庫信息變?yōu)椋?000013 號(hào)信息已經(jīng)刪除6、 退出系統(tǒng)功能下拉菜單客戶信息管理選擇退出:然后就退出了界面。三、 程序源代碼 package LoginSystem; import java.sql.*; import java.io.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.event.*;/ 登錄界面

4、public class Login extends JFrameprivate TextField nameField = new TextField(10);private JPasswordField passwordField = new JPasswordField(15);private JButton loginButton = new JButton(登 錄 );private JButton exitButton = new JButton(退 出 );private JLabel titleLabel = new JLabel(夢(mèng) 之路時(shí)尚天堂商品管理系統(tǒng) );privat

5、e JLabel userLabel = new JLabel用( 戶名 );private JLabel pwdLabel = new JLabel(密碼 );private String user = null;private char pwd = null;public static void main(String args)Login frame = new Login(); frame.setTitle( 系統(tǒng)登錄 ); frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); frame.setResizable(fa

6、lse);frame.setLocation(600,300);frame.pack();frame.setVisible(true);public Login()JPanel titlePanels = new JPanel(); titlePanels.add(titleLabel); titleLabel.setFont(new java.awt.Font(Dialog,1,28); titleLabel.setForeground(Color.red);JPanel labelPanels = new JPanel(); labelPanels.setLayout(new GridLa

7、yout(2,1,10,40); labelPanels.add(userLabel);labelPanels.add(pwdLabel);JPanel textFieldPanels = new JPanel(); textFieldPanels.setLayout(new GridLayout(2,1,10,40); textFieldPanels.add(nameField); textFieldPanels.add(passwordField);JPanel buttonPanels = new JPanel(); buttonPanels.add(loginButton); butt

8、onPanels.add(exitButton);JPanel picturePanels = new JPanel();JLabel lb = new JLabel(new ImageIcon(A.png);picturePanels.add(lb);JPanel dialogPanels = new JPanel(); dialogPanels.setLayout(new BorderLayout(); dialogPanels.add(titlePanels,BorderLayout.NORTH); dialogPanels.add(labelPanels,BorderLayout.WE

9、ST); dialogPanels.add(textFieldPanels,BorderLayout.CENTER); dialogPanels.add(buttonPanels,BorderLayout.SOUTH); dialogPanels.add(picturePanels,BorderLayout.EAST); add(dialogPanels);exitButton.addActionListener(new ActionListener() public void actionPerformed(ActionEvent event)System.exit(0););loginBu

10、tton.addActionListener(new ActionListener() public void actionPerformed(ActionEvent event) Connection con=Login.getConnection(); tryStatement state=con.createStatement();user = nameField.getText();pwd = passwordField.getPassword();String pwds = new String(pwd);String sql = select 密碼 from 操作人員 where

11、用戶名=+user+;ResultSet rs = state.executeQuery(sql);rs.next();if(pwds.equals()|user.equals()JOptionPane.showMessageDialog(null,用戶名或密碼不 能為空! ,錯(cuò)誤 ,JOptionPane.ERROR_MESSAGE);else if(!(rs.getString(密碼 ).equals(pwds) JOptionPane.showMessageDialog(null,用戶名或密碼錯(cuò) 誤! ,錯(cuò)誤 ,JOptionPane.ERROR_MESSAGE);elsenew Goo

12、ds();dispose();Login.closeConn(con);Login.closeState(state);Login.closeRs(rs);catch(SQLException e)JOptionPane.showMessageDialog(null,用戶名或密碼錯(cuò)誤!,錯(cuò)誤 ,JOptionPane.ERROR_MESSAGE););public static void closeConn(Connection conn)try if(conn != null)conn.close(); catch (SQLException e) e.printStackTrace();p

13、ublic static void closeState(Statement state) try if(state != null)state.close(); catch (SQLException e) e.printStackTrace();public static void closeRs(ResultSet rs) try if(rs != null)rs.close(); catch (SQLException e) e.printStackTrace();/ 連接數(shù)據(jù)庫public static Connection getConnection()String driverN

14、ame = com.microsoft.sqlserver.jdbc.SQLServerDriver;String dbURL = jdbc:sqlserver:/localhost:1433;DatabaseName= 夢(mèng)之路時(shí)尚天堂商品管理系統(tǒng) ;String userName = sa;String userPwd = 123;Connection conn=null;try Class.forName(driverName);conn = DriverManager.getConnection(dbURL, userName, userPwd);catch (Exception e)e

15、.printStackTrace();return conn;/ 菜單界面class Goodsprivate static final long serialVersionUID=1L;static final int WIDTH=760;static final int HEIGHT=510;JPopupMenu pop;JMenuItem item2;JFrame f;JMenuItem item1;JPanel p;JTabbedPane tp;public Goods()f=new JFrame(夢(mèng)之路時(shí)尚天堂商品管理系統(tǒng) );JMenuBar menubar1=new JMenuB

16、ar();tp=new JTabbedPane();p=new JPanel();f.setJMenuBar(menubar1);f.add(p);p.add(tp);JMenu menu1=new JMenu(顧客信息系統(tǒng) ); menu1.setMnemonic(Z);menubar1.add(menu1);JMenuItem item1=new JMenuItem( 添加客戶信息 ); JMenuItem item2=new JMenuItem( 修改客戶信息 ); JMenuItem item3=new JMenuItem( 查詢客戶信息 ); JMenuItem item4=new

17、JMenuItem( 刪除客戶信息 ); JMenuItem item5=new JMenuItem( 退出 );item1.setAccelerator(KeyStroke.getKeyStroke(A,java.awt.Event.CTRL_MASK,false);item2.setAccelerator(KeyStroke.getKeyStroke(U,java.awt.Event.CTRL_MASK,false);item3.setAccelerator(KeyStroke.getKeyStroke(S,java.awt.Event.CTRL_MASK,false);item4.set

18、Accelerator(KeyStroke.getKeyStroke(D,java.awt.Event.CTRL_MASK,false);item5.setAccelerator(KeyStroke.getKeyStroke(E,java.awt.Event.CTRL_MASK,false); menu1.add(item1);menu1.add(item2);menu1.add(item3);menu1.add(item4);menu1.add(item5);f.add(p);JLabel lb = new JLabel(new ImageIcon(SC.jpg);p.add(lb);f.s

19、etVisible(true);f.setSize(WIDTH,HEIGHT);Toolkit kit=Toolkit.getDefaultToolkit();Dimension screenSize=kit.getScreenSize();int width=screenSize.width;int height=screenSize.height;int x=(width-WIDTH)/2;int y=(height-HEIGHT)2/ ;f.setLocation(x,y);item1.addActionListener(new ActionListener()public void a

20、ctionPerformed(ActionEvent Event)Add con1=new Add();tp.addTab(添加客戶信息 ,con1);tp.setEnabledAt(0,true);tp.setTitleAt(0, 添加客戶信息 );tp.setPreferredSize(new Dimension(500,200);tp.setTabPlacement(JTabbedPane.TOP);tp.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT););item2.addActionListener(new ActionListen

21、er()public void actionPerformed(ActionEvent Event)Update con2=new Update();tp.addTab(修改客戶信息 ,con2);tp.setEnabledAt(0,true);tp.setTitleAt(0, 修改客戶信息 );tp.setPreferredSize(new Dimension(500,200);tp.setTabPlacement(JTabbedPane.TOP);tp.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); );item3.addActionL

22、istener(new ActionListener()public void actionPerformed(ActionEvent Event)Select con3=new Select();tp.addTab(查詢客戶信息 ,con3);tp.setEnabledAt(0,true);tp.setTitleAt(0, 查詢客戶信息 );tp.setPreferredSize(new Dimension(500,200);tp.setTabPlacement(JTabbedPane.TOP);tp.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAY

23、OUT););item4.addActionListener(new ActionListener()public void actionPerformed(ActionEvent Event)Delect con4=new Delect();tp.addTab(刪除客戶信息 ,con4);tp.setEnabledAt(0,true);tp.setTitleAt(0, 刪除客戶信息 );tp.setPreferredSize(new Dimension(500,200);tp.setTabPlacement(JTabbedPane.TOP);tp.setTabLayoutPolicy(JTa

24、bbedPane.SCROLL_TAB_LAYOUT););item5.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)System.exit(0););menu1.addMenuListener(new MenuListener()public void menuSelected(MenuEvent event) item2.setEnabled(!item1.isSelected();public void menuDeselected(MenuEvent event) publ

25、ic void menuCanceled(MenuEvent event) );/ 信息添加class Add extends JPanely,int w,int h)public void add(Component c,GridBagConstraintsc onstraints,int x,intconstraints.gridx=x; constraints.gridy=y; constraints.gridwidth=w; constraints.gridheight=h; add(c,constraints);Add()GridBagLayout lay=new GridBagLa

26、yout(); setLayout(lay);JButton ok=new JButton(確 定 );JButton clear=new JButton(清 空 );JButton c=new JButton(關(guān)閉 );JLabel name=new JLabel(姓 名 );JLabel phone=new JLabel(電 話號(hào)碼 );JLabel sex=new JLabel(性 別 );JLabel num=new JLabel(客 戶編碼 );JLabel years=new JLabel(年 齡 );Font font=new Font(Serief, Font.BOLD, 22

27、); final JTextField nameinput=new JTextField(10); final JTextField phoneinput=new JTextField(10); final JTextField sexinput=new JTextField(10); final JTextField numinput=new JTextField(10); final JTextField yearsinput=new JTextField(10); JLabel title=new JLabel(顧客基本信息 ); title.setFont(font); title.s

28、etForeground(Color.blue);JButton additionbutton=new JButton(添加 ); GridBagConstraints constraints=new GridBagConstraints(); constraints.fill=GridBagConstraints.NONE; constraints.weightx=4; constraints.weighty=7;add(title,constraints,0,0,4,1); add(num,constraints,0,4,1,1); add(name,constraints,0,1,1,1

29、); add(phone,constraints,0,5,1,1);add(sex,constraints,0,3,1,1); add(years,constraints,0,2,1,1);add(nameinput,constraints,1,1,1,1);add(phoneinput,constraints,1,5,1,1);add(sexinput,constraints,1,3,1,1);add(numinput,constraints,1,4,1,1);add(yearsinput,constraints,1,2,1,1);add(ok,constraints,3,1,1,1);ad

30、d(clear,constraints,3,3,1,1);add(c,constraints,3,5,1,1);c.addActionListener(new ActionListener()public void actionPerformed(ActionEvent Event)removeAll(););ok.addActionListener(new ActionListener()public void actionPerformed(ActionEvent Event)tryClass.forName(com.microsoft.sqlserver.jdbc.SQLServerDr

31、iver);catch(ClassNotFoundException ex) String url=jdbc:sqlserver:/localhost:1433; DatabaseName=夢(mèng)之路時(shí)尚天堂商品管理系統(tǒng) ;String user=sa;String password=123;Statement stmt;ResultSet rs;PreparedStatement prestmt;String nametext=nameinput.getText();String phonetext=phoneinput.getText();String sextext=sexinput.get

32、Text();String numtext=numinput.getText();String yearstext=yearsinput.getText();tryConnection con=DriverManager.getConnection(url,user,password);prestmt=con.prepareStatement(INSERT INTO customer 顧 客VALUES(?,?,?,?,?) );prestmt.setString(5,phonetext);prestmt.setString(2,nametext);prestmt.setString(4,se

33、xtext);prestmt.setString(1,numtext);prestmt.setString(3,yearstext);prestmt.executeUpdate();con.close();JOptionPane.showMessageDialog(null, 信 息 添 加 成 功 ,OK,JOptionPane.INFORMATION_MESSAGE);catch(SQLException ex) );clear.addActionListener(new ActionListener()public void actionPerformed(ActionEvent Eve

34、nt)nameinput.setText(); phoneinput.setText(); sexinput.setText(); numinput.setText(); yearsinput.setText(););/ 信息修改class Update extends JPanelpublic void add(Component c,GridBagConstraintsc onstraints,int x,inty,int w,int h)constraints.gridx=x;constraints.gridy=y;constraints.gridwidth=w;constraints.

35、gridheight=h;add(c,constraints);Update()GridBagLayout lay=new GridBagLayout();setLayout(lay);JButton ok=new JButton(確 定 );JButton clear=new JButton(清 空 );JButton c=new JButton(關(guān)閉 );JLabel name=new JLabel(姓 名 );JLabel phone=new JLabel(電 話號(hào)碼 );JLabel sex=new JLabel(性 別 );JLabel num=new JLabel(客 戶編碼 );

36、JLabel years=new JLabel(年 齡 );final JTextField nameinput=new JTextField(10);final JTextField phoneinput=new JTextField(10);final JTextField sexinput=new JTextField(10); final JTextField numinput=new JTextField(10); final JTextField yearsinput=new JTextField(10); JLabel title=new JLabel(修改基本信息 ); Fon

37、t font=new Font(Serief, Font.BOLD, 22); title.setFont(font); title.setForeground(Color.blue);/設(shè)置標(biāo)簽前景色 JButton additionbutton=new JButton(添加 ); GridBagConstraints constraints=new GridBagConstraints(); constraints.fill=GridBagConstraints.NONE; constraints.weightx=4;constraints.weighty=7; add(title,con

38、straints,0,0,4,1); add(name,constraints,0,1,1,1); add(phone,constraints,0,5,1,1); add(sex,constraints,0,3,1,1); add(num,constraints,0,4,1,1); add(nameinput,constraints,1,1,1,1); add(phoneinput,constraints,1,5,1,1); add(sexinput,constraints,1,3,1,1); add(numinput,constraints,1,4,1,1); add(years,const

39、raints,0,2,1,1); add(yearsinput,constraints,1,2,1,1);add(ok,constraints,3,1,1,1); add(clear,constraints,3,3,1,1); add(c,constraints,3,5,1,1);c.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) removeAll(); );ok.addActionListener(new ActionListener()public void actionP

40、erformed(ActionEvent Event)try Class.forName(com.microsoft.sqlserver.jdbc.SQLServerDriver); catch(ClassNotFoundException ex) String url=jdbc:sqlserver:/localhost:1433; DatabaseName=夢(mèng)之路時(shí) 尚天堂商品管理系統(tǒng) ;String user=sa;String password=123;Statement stmt;ResultSet rs;PreparedStatement prestmt;String nametex

41、t=nameinput.getText();String phonetext=phoneinput.getText();String sextext=sexinput.getText();String numtext=numinput.getText();String yearstext=yearsinput.getText();tryConnection conn= DriverManager.getConnection(url,user,password); prestmt=conn.prepareStatement(update customer 顧 客 set cname=?,csex

42、=?,ctelephone=?,cage=? WHERE cno=?);prestmt.setString(1,nametext);prestmt.setString(2,sextext);prestmt.setString(5,numtext);prestmt.setString(4,yearstext);prestmt.setString(3,phonetext);prestmt.executeUpdate();prestmt.close();conn.close();JOptionPane.showMessageDialog(null, 信 息 修 改 成 功,OK,JOptionPan

43、e.INFORMATION_MESSAGE);catch(SQLException ex) ex.printStackTrace(););clear.addActionListener(new ActionListener()public void actionPerformed(ActionEvent Event)nameinput.setText();phoneinput.setText();sexinput.setText();numinput.setText();yearsinput.setText(););/ 信息刪除class Delect extends JPanelpublic

44、 void add(Component c,GridBagConstraints constraints,int x,int y,int w,int h)constraints.gridx=x; constraints.gridy=y; constraints.gridwidth=w; constraints.gridheight=h; add(c,constraints);Delect()GridBagLayout lay=new GridBagLayout();setLayout(lay);JButton ok=new JButton(確定刪除此顧客 !);JButton clear=ne

45、w JButton(清 空 );JLabel c=new JLabel(客 戶編碼 );Font font=new Font(Serief, Font.BOLD, 22);c.setFont(font); c.setForeground(Color.blue);/設(shè)置標(biāo)簽前景色 final JTextField d=new JTextField(16); JLabel title=new JLabel(識(shí)別信息 ); JButton additionbutton=new JButton(添加 ); GridBagConstraints constraints=new GridBagConstr

46、aints(); constraints.fill=GridBagConstraints.NONE; constraints.weightx=4;constraints.weighty=6; add(c,constraints,0,1,1,1); add(d,constraints,1,1,1,1); add(ok,constraints,0,2,1,1); add(clear,constraints,1,2,1,1);ok.addActionListener(new ActionListener()public void actionPerformed(ActionEvent Event)t

47、ryClass.forName(com.microsoft.sqlserver.jdbc.SQLServerDriver); catch(ClassNotFoundException ex) String url=jdbc:sqlserver:/localhost:1433; DatabaseName=夢(mèng)之路時(shí) 尚天堂商品管理系統(tǒng) ;String user=sa;String password=123;Statement stmt;ResultSet rs;PreparedStatement prestmt;try Connection conn= DriverManager.getConne

48、ction(url,user,password);prestmt=conn.prepareStatement(DELETE FROM customer 顧 客WHERE cno=?);prestmt.setString(1,d.getText();prestmt.executeUpdate();prestmt.close(); conn.close(); JOptionPane.showMessageDialog(null, 該 顧 客 記 錄 已 刪 除 ,OK,JOptionPane.INFORMATION_MESSAGE); catch(SQLException ex) );clear.

49、addActionListener(new ActionListener()public void actionPerformed(ActionEvent Event) d.setText(););/ 顧客信息查詢class Select extends JPanelpublic void add(Component c,GridBagConstraints constraints,int x,int y,int w,int h)constraints.gridx=x; constraints.gridy=y; constraints.gridwidth=w; constraints.grid

50、height=h; add(c,constraints);Select()GridBagLayout lay=new GridBagLayout(); setLayout(lay); JButton ok=new JButton(確定查詢此顧客 ); JButton clear=new JButton(清 空 ); JLabel c=new JLabel(客 戶編碼 ); final JTextField d=new JTextField(16); JLabel title=new JLabel(識(shí)別信息 ); JButton additionbutton=new JButton(添加 );

51、JLabel name=new JLabel(姓 名 ); JLabel id=new JLabel(客 戶編碼 ); JLabel sex=new JLabel(性 別 ); JLabel num=new JLabel(電 話號(hào)碼 ); JLabel years=new JLabel(年 齡 ); final JTextField nameinput=new JTextField(10); final JTextField idinput=new JTextField(10); final JTextField sexinput=new JTextField(10); final JTextField numinput=new JTextField(10); final JTextField yearsinput=new JTextFiel

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(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ì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論