面向对象课程设计java大作业报告源代码

上传人:无*** 文档编号:44316286 上传时间:2021-12-05 格式:DOC 页数:22 大小:1.08MB
收藏 版权申诉 举报 下载
面向对象课程设计java大作业报告源代码_第1页
第1页 / 共22页
面向对象课程设计java大作业报告源代码_第2页
第2页 / 共22页
面向对象课程设计java大作业报告源代码_第3页
第3页 / 共22页
资源描述:

《面向对象课程设计java大作业报告源代码》由会员分享,可在线阅读,更多相关《面向对象课程设计java大作业报告源代码(22页珍藏版)》请在装配图网上搜索。

1、Java程序设计报告年级专业 信息管理与信息系统 学 号 学生姓名 指导教师 二一四年六月 一、所用到的表的结构及数据类型 customer顾客表表名customer顾客说明此表记录顾客基本信息列名说明数据类型约束cno顾客编号char(10)主码cname顾客姓名char(10)cage年龄intcsex性别char(2)取值为男或女,默认女ctelephone顾客联系方式char(15)非空操作人员表表名操作人员说明此表记录操作人员信息列名说明数据类型约束用户名用户登录名nchar(10)主码密码登录密码nchar(3)非空职位担任职务nchar(10)二、程序的功能及实现结果截图1、 登

2、录功能打开Java文件Login.java运行后输入错误的用户名后出现:输入用户名Lucy 密码:123点击登录进入操作界面:2、 添加功能下拉顾客信息系统菜单,选择添加客户信息添加信息前数据库客户表的内容:没有编号0000013添加客户0000013:张蔷,29,女,0000013,13224463243数据库内表变为:注:0000015号是截图之前添加进去的3、 查询功能下拉客户信息系统菜单,选择查询客户信息,输入客户编码0000013后点击确定查询此顾客:4、 修改功能下拉菜单客户信息系统,选择修改客户信息,重新输入相应的正确信息,将错误的覆盖掉,此处将0000013张蔷年龄改为32:数

3、据库表内内容:5、 删除功能下拉菜单客户信息系统,选择删除客户信息,输入客户编码0000013点击确认:数据库信息变为:0000013号信息已经删除6、 退出系统功能下拉菜单客户信息管理选择退出:然后就退出了界面。三、 程序源代码package LoginSystem;import java.sql.*;import java.io.*;import javax.swing.*;import java.awt.*;import java.awt.event.*;import javax.swing.event.*; /登录界面public class Login extends JFramep

4、rivate 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(梦之路时尚天堂商品管理系统);private JLabel userLabel = new JLabel(用户名);p

5、rivate JLabel pwdLabel = new JLabel(密 码);private String user = null;private char pwd = null;public static void main(String args)Login frame = new Login();frame.setTitle(系统登录);frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);frame.setResizable(false);frame.setLocation(600,300);frame.pack();

6、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 GridLayout(2,1,10,40);labelPanels.add(userLabel);labelP

7、anels.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);buttonPanels.add(exitButton);JPanel picturePanels = new JPa

8、nel();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.WEST);dialogPanels.add(textFieldPanels,BorderLayout.CENTER)

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

10、erformed(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 用户名 =+user+;ResultSet rs = state.executeQuery(sql);rs.next();if(p

11、wds.equals()|user.equals()JOptionPane.showMessageDialog(null,用户名或密码不能为空!,错误,JOptionPane.ERROR_MESSAGE);else if(!(rs.getString(密码).equals(pwds)JOptionPane.showMessageDialog(null,用户名或密码错误!,错误,JOptionPane.ERROR_MESSAGE);elsenew Goods();dispose();Login.closeConn(con);Login.closeState(state);Login.closeR

12、s(rs);catch(SQLException e)JOptionPane.showMessageDialog(null,用户名或密码错误!,错误,JOptionPane.ERROR_MESSAGE););public static void closeConn(Connection conn)try if(conn != null)conn.close(); catch (SQLException e) e.printStackTrace();public static void closeState(Statement state) try if(state != null)state.

13、close(); catch (SQLException e) e.printStackTrace();public static void closeRs(ResultSet rs) try if(rs != null)rs.close(); catch (SQLException e) e.printStackTrace();/连接数据库public static Connection getConnection()String driverName = com.microsoft.sqlserver.jdbc.SQLServerDriver;String dbURL = jdbc:sql

14、server:/localhost:1433;DatabaseName=梦之路时尚天堂商品管理系统; String userName = sa; String userPwd = 123; Connection conn=null; try Class.forName(driverName); conn = DriverManager.getConnection(dbURL, userName, userPwd); catch (Exception e) e.printStackTrace(); return conn;/菜单界面class Goodsprivate static final

15、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(梦之路时尚天堂商品管理系统);JMenuBar menubar1=new JMenuBar();tp=new JTabbedPane();p=new JPanel();f.setJMenuBar(menubar1);f.add

16、(p);p.add(tp);JMenu menu1=new JMenu(顾客信息系统);menu1.setMnemonic(Z);menubar1.add(menu1); JMenuItem item1=new JMenuItem(添加客户信息); JMenuItem item2=new JMenuItem(修改客户信息); JMenuItem item3=new JMenuItem(查询客户信息); JMenuItem item4=new JMenuItem(删除客户信息); JMenuItem item5=new JMenuItem(退出); item1.setAccelerator(Ke

17、yStroke.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.setAccelerator(KeyStroke.getKeyStroke(D,java.awt.Event.CTRL_MASK,false); item5.s

18、etAccelerator(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.setVisible(true); f.setSize(WIDTH,HEIGHT); Toolkit kit=Toolkit.getDef

19、aultToolkit(); 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 actionPerformed(ActionEvent Event) Add con1=new Add(); tp.ad

20、dTab(添加客户信息,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 ActionListener() public void actionPerformed(ActionEvent Event) U

21、pdate 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.addActionListener(new ActionListener() public void action

22、Performed(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_LAYOUT); ); item4.addActionListener(new Actio

23、nListener() 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(JTabbedPane.SCROLL_TAB_LAYOUT); ); ite

24、m5.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) public void menuCanceled(MenuEv

25、ent event) ); /信息添加 class Add extends JPanel public 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); Add() GridBagLayout lay=new GridBagLayout(); setLayout(lay

26、); JButton ok=new JButton(确 定); JButton clear=new JButton(清 空); JButton c=new JButton(关闭); JLabel name=new JLabel(姓名); JLabel phone=new JLabel(电话号码); JLabel sex=new JLabel(性别); JLabel num=new JLabel(客户编码); JLabel years=new JLabel(年龄); Font font=new Font(Serief, Font.BOLD, 22); final JTextField namei

27、nput=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.setForeground(Color.blue);

28、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); add(phone,constraints,

29、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); add(clear,constrain

30、ts,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) try Class.forName(com.microsoft.sqlserver.jdbc.SQLServerDriver); c

31、atch(ClassNotFoundException ex) String url=jdbc:sqlserver:/localhost:1433; DatabaseName=梦之路时尚天堂商品管理系统;String user=sa;String password=123; Statement stmt; ResultSet rs; PreparedStatement prestmt;String nametext=nameinput.getText(); String phonetext=phoneinput.getText(); String sextext=sexinput.getTex

32、t(); 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 Event)

34、nameinput.setText(); phoneinput.setText(); sexinput.setText(); numinput.setText(); yearsinput.setText(); ); /信息修改 class Update extends JPanel public void add(Component c,GridBagConstraints constraints,int x,int y,int w,int h) constraints.gridx=x; constraints.gridy=y; constraints.gridwidth=w; constra

35、ints.gridheight=h; add(c,constraints); Update() GridBagLayout lay=new GridBagLayout(); setLayout(lay); JButton ok=new JButton(确 定); JButton clear=new JButton(清 空); JButton c=new JButton(关闭); JLabel name=new JLabel(姓名); JLabel phone=new JLabel(电话号码); 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(修改基本信息

37、); Font font=new Font(Serief, Font.BOLD, 22); title.setFont(font); title.setForeground(Color.blue);/设置标签前景色 JButton additionbutton=new JButton(添加); GridBagConstraints constraints=new GridBagConstraints(); constraints.fill=GridBagConstraints.NONE; constraints.weightx=4; constraints.weighty=7; add(tit

38、le,constraints,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,

39、constraints,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 voi

40、d actionPerformed(ActionEvent Event) try Class.forName(com.microsoft.sqlserver.jdbc.SQLServerDriver); catch(ClassNotFoundException ex) String url=jdbc:sqlserver:/localhost:1433; DatabaseName=梦之路时尚天堂商品管理系统;String user=sa;String password=123; Statement stmt; ResultSet rs; PreparedStatement prestmt;Str

41、ing nametext=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

42、 cname=?,csex=?,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,JOp

43、tionPane.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 ext

44、ends JPanel public 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(确定删除

45、此顾客!); JButton clear=new JButton(清 空); JLabel c=new JLabel(客户编码); Font font=new Font(Serief, Font.BOLD, 22); c.setFont(font); c.setForeground(Color.blue);/设置标签前景色 final JTextField d=new JTextField(16); JLabel title=new JLabel(识别信息); JButton additionbutton=new JButton(添加); GridBagConstraints constrai

46、nts=new GridBagConstraints(); 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 actionPerfo

47、rmed(ActionEvent Event) try Class.forName(com.microsoft.sqlserver.jdbc.SQLServerDriver); catch(ClassNotFoundException ex) String url=jdbc:sqlserver:/localhost:1433; DatabaseName=梦之路时尚天堂商品管理系统;String user=sa;String password=123; Statement stmt; ResultSet rs; PreparedStatement prestmt; try Connection

48、conn= DriverManager.getConnection(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.addActionListener(new ActionListener() public void actionPerformed(ActionEvent Event) d.setText(); ); /顾客信息查询 cla

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!