java课程设计 - 图文

更新时间:2024-04-28 01:41:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

课程设计 小规模实用软件的设计 1、 实验目的 ? 掌握实际开发的步骤。 ? 能够熟练开发和学生管理系统相类似的系统。 ? 掌握Java中的界面开发。 ? 掌握Java中如何连接数据库。 2、 实验设备及仪器 计算机一台,配置有JDK环境 3、 实验内容 自行设计一个小规模实用软件,如学生成绩管理、同学通讯录管理、小游戏等。 编写学生管理系统程序,利用图形界面构造系统的客户端服务界面,连接数据库,使得学生教师能简单方便地对数据进行存储修改 4、 实验步骤 (1) 首先确定学生管理系统的用户。 (2) 学生管理系统的用户基本分为两类,分别是老师和学生。不管是哪种用户都是必须经过登录才能进入学生管理系统的,所以该系统必须有一个登录界面,并且在该界面中能够让用户选择用户是老师还是学生。该系统是不会对外开放的,所以也不存在注册界面。 (3) 因为用户分为两种,所以每一种用户进行操作的界面应该是不同的。首先是学生界面,在其中应该只有查询成绩和个人信息查询和插入。主要来学习如何进行学生界面开发。 (4) 除了学生界面外,还要有一个老师界面。老师在老师界面中可以对学生信息进行管理,包括查询、修改和删除。同样也可以对学生的成绩进行管理,包括查询和插入,由于输入错误还要能够对学生的成绩进行修改,由于学生作弊还能够将学生的成绩进行删除。 (5) 首先数据库中应该有老师和学生这两个表,表中应该最少有用户名和密码两项,使用表中的这两项就可以进行登录。在学生表中还应该具有一些和学籍相关的信息,包括年龄、班级等内容,这样就可以在系统中对学生信息进行操作。 (6) 除此之外还需要一个成绩表,通过该表老师可以对学生的成绩进行查询、插入、修改和删除。学生也可以通过该表对自己的成绩进行查询。 (7) 不管是老师和学生进入学生管理系统都是从登录界面进入的。在登录界面中应该是让用户选择自己身份的,然后系统将根据用户的选择来判断用户的身份并进行查询不同的数据库。 (8) 对界面设计好基本形式后,就可以进行程序开发。首先要定义两个标签和两个文本框,分别来表示用户名和密码。并且还需要定义一个下拉列表让用户来进行身份选择,其中选项包括“学生”和“老师”。在程序的最后还定义了两个按钮,从而让用户输入用户名和密码后进行登录。 (9) 在学生界面中,学生可以对自己的信息进行查询,在第一次登录时还可以对自己的信息进行插入,并且学生能够查询自己的成绩。 (10) 因为学生要完成对信息和成绩的操作,所以这里的设计是在界面中定义两个菜(11) (12) (13) (14) 单,分别进行信息和成绩的操作。因为对信息的操作包括插入和查询,所以还需要在信息菜单下定义“插入”和“查询”两个子菜单。 对界面进行设计后,就可以进行程序开发。同样首先是创建一个窗口,在窗口中要创建两个菜单,并且在信息菜单下还要创建“插入”和“查询”两个子菜单。 在学生界面中单击“信息”菜单下的“插入”子菜单,就会进入学生插入界面,在该界面中学生可以输入自己的信息。 学生第一次插入信息后,老师是可以对学生的信息进行修改和删除的。除此之外,学生还可以查询自己被修改后的信息,在信息菜单下有一个查询子菜单,单击该菜单就触发事件,从而进入查询学生信息界面。 在学生界面中还有一个“成绩”菜单,在学生的界面该菜单下只有一个“查询”子菜单。单击“查询”子菜单,将触发事件,进入到查询成绩界面。 5、 附录 (1) 登陆界面 import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.sql.*; public class systems extends JFrame implements ActionListener { static systems ss; JPanel panel = new JPanel(); JLabel label1 = new JLabel(\输入姓名:\ JTextField name = new JTextField(); JLabel label2 = new JLabel(\密 码:\ JPasswordField pwd = new JPasswordField(); JButton Enter = new JButton(\登录\ JButton Exit = new JButton(\退出\ String url = \ ButtonGroup bgp = new ButtonGroup(); JRadioButton stu = new JRadioButton(\学生\ JRadioButton tch = new JRadioButton(\教师\ public systems() { super(\登录系统\ this.setResizable(false); JLabel img = new JLabel(new ImageIcon(url)); img.setBounds(0,0,500,100); panel.add(img); stu.setBounds(165,210,70,20); tch.setBounds(265,210,70,20); bgp.add(stu); bgp.add(tch); panel.add(stu); panel.add(tch); Enter.setBounds(150,250,80,20); Exit.setBounds(270,250,80,20); Enter.addActionListener(this); Exit.addActionListener(this); panel.add(Enter); panel.add(Exit); panel.setLayout(null); this.add(panel); label1.setBounds(135,130,100,25); panel.add(label1); name.setBounds(265,130,100,25); panel.add(name); label2.setBounds(135,165,100,25); panel.add(label2); pwd.setBounds(265,165,100,25); panel.add(pwd); this.setBounds(100,100,500,350); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public void actionPerformed(ActionEvent e) { if(e.getSource()==Enter) { String username , password; username = name.getText(); password = pwd.getText(); try { Class.forName(\ } catch (ClassNotFoundException ce) { JOptionPane.showMessageDialog(ss,ce.getMessage()); } if(stu.isSelected()) { try { Connection con = DriverManager.getConnection(\ Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(\ while(rs.next()) { if((rs.getString(\assword))) { JOptionPane.showMessageDialog(ss,\登陆成功\ 败\ Students stu = new Students(); } else { JOptionPane.showMessageDialog(ss,\登录失 } } rs.close(); stmt.close(); } catch (SQLException se) { JOptionPane.showMessageDialog(ss,se.getMessage()); } } else if(tch.isSelected()) { try { Connection con = DriverManager.getConnection(\ Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(\ while(rs.next()) { if((rs.getString(\assword))) { JOptionPane.showMessageDialog(ss,\登陆成功\ 败\} else { JOptionPane.showMessageDialog(ss,\登录失(2) } } } catch (SQLException se) { JOptionPane.showMessageDialog(ss,se.getMessage()); } } } else { System.exit(0); } } public static void main(String[] args) { systems sys = new systems(); } } 学生界面 import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Students extends JFrame implements ActionListener { JMenuBar jmb = new JMenuBar(); JMenu Message = new JMenu(\信息\ JMenu Score = new JMenu(\成绩\ JMenuItem Item1 = new JMenuItem(\插入\ JMenuItem Item2 = new JMenuItem(\查询\ JMenuItem Item3 = new JMenuItem(\查询\

public Students() { super(\学生界面\ this.setSize(500,400); this.setVisible(true); this.setResizable(false); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setJMenuBar(jmb); jmb.add(Message); jmb.add(Score); Message.add(Item1); Message.add(Item2); Score.add(Item3); Item1.addActionListener(this); Item2.addActionListener(this); Item3.addActionListener(this); } public void actionPerformed(ActionEvent e) { if(e.getSource()==Item1) { AddMsg ad = new AddMsg(); } else if(e.getSource()==Item2) { Serch ser = new Serch(); } else { Score so = new Score(); } } public static void main(String[] args) { Students stu = new Students(); } } 添加学生信息 import java.awt.*; import javax.swing.*; (3) import java.awt.event.*; import java.sql.*; public class AddMsg extends JFrame implements ActionListener { static AddMsg s; /*添加学生信息控件*/ JPanel jpl = new JPanel(); JLabel label1 = new JLabel(\添加基本信息\ JLabel label2 = new JLabel(\学号:\ JLabel label3 = new JLabel(\姓名:\ JLabel label4 = new JLabel(\性别:\ JLabel label5 = new JLabel(\班级:\ JLabel label6 = new JLabel(\学院:\ JTextField num = new JTextField(2); JTextField nam = new JTextField(4); ButtonGroup bgp = new ButtonGroup(); JRadioButton man = new JRadioButton(\男\ JRadioButton women = new JRadioButton(\女\ JTextField clas = new JTextField(); JTextField scl = new JTextField(); JButton reset = new JButton(\重置\ JButton addmsg = new JButton(\添加\ public AddMsg() { super(\添加学生信息\ this.setResizable(false); this.setSize(500,400); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.add(jpl); jpl.setLayout(null); addmsg.addActionListener(this); reset.addActionListener(this); /*插入面板*/ label1.setBounds(100,20,300,20); jpl.add(label1); label2.setBounds(100,50,70,20); jpl.add(label2); num.setBounds(190,50,140,20); jpl.add(num); label3.setBounds(100,90,70,20); jpl.add(label3); nam.setBounds(190,90,140,20); jpl.add(nam); label4.setBounds(100,130,70,20); jpl.add(label4); man.setBounds(190,130,60,20); women.setBounds(270,130,60,20); jpl.add(man); jpl.add(women); bgp.add(man); bgp.add(women); label5.setBounds(100,170,70,20); jpl.add(label5); clas.setBounds(190,170,140,20); jpl.add(clas); label6.setBounds(100,210,70,20); jpl.add(label6); scl.setBounds(190,210,140,20); jpl.add(scl); reset.setBounds(120,250,90,20); addmsg.setBounds(240,250,90,20); jpl.add(reset); jpl.add(addmsg); } public void actionPerformed(ActionEvent e) { if(e.getSource()==addmsg) { String sex; if(man.isSelected()) { sex=\男\ } else { sex=\女\ } try { Class.forName(\ } catch (ClassNotFoundException ce) { JOptionPane.showMessageDialog(s,ce.getMessage()); } try { Connection con = DriverManager.getConnection(\ Statement stmt = con.createStatement(); int a = stmt.executeUpdate(\into STU(ID , Pwd , Name , Sex , Class , Collage)values('\+sex+\ if(a==1) { JOptionPane.showMessageDialog(s,\已成功添加\ } else { JOptionPane.showMessageDialog(s,\添加失败\ } stmt.close(); } catch (SQLException se) { JOptionPane.showMessageDialog(s,se.getMessage()); } } else { num.setText(\ nam.setText(\ clas.setText(\ scl.setText(\ num.requestFocus(); } } public static void main(String[] args) { AddMsg amg = new AddMsg(); } } 添加学生成绩 import java.awt.*; (4) import javax.swing.*; import java.awt.event.*; import java.sql.*; public class Addscore extends JFrame implements ActionListener { static Addscore ss; JLabel[] label = {new JLabel(\学号:\计算机网络:\JLabel(\操作系统:\计算机专业英语:\计算机信息技术基础:\程序设计:\数据库应用实训教程:\高等数学:\:\ JTextField[] txt = {new JTextField() , new JTextField() , new JTextField() , new JTextField() , new JTextField() ,new JTextField() , new JTextField() ,new JTextField() ,new JTextField() }; JButton add = new JButton(\添加\ JButton reset = new JButton(\重置\ JPanel jpl = new JPanel(); JLabel title = new JLabel(\添加学生成绩\ Font f = new Font(\黑体\ int s = 100; public Addscore() { super(\添加学生信息\ this.setResizable(false); this.setSize(500,600); this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setVisible(true); this.add(jpl); add.addActionListener(this); reset.addActionListener(this); jpl.setLayout(null); title.setBounds(150,40,200,20); title.setFont(f); title.setForeground(Color.red); jpl.setBackground(Color.LIGHT_GRAY); jpl.add(title); for(int i = 0 ; i

} add.setBounds(150,s,80,20); reset.setBounds(250,s,80,20); jpl.add(add); jpl.add(reset); } public void actionPerformed(ActionEvent e) { if(e.getSource()==add) { try { Class.forName(\ } catch (ClassNotFoundException ce) { JOptionPane.showMessageDialog(ss,ce.getMessage()); } try { Connection con = DriverManager.getConnection(\ Statement stmt = con.createStatement(); int a = stmt.executeUpdate(\计算机系成绩(SID , 计算机网络 , Linux操作系统 , 计算机专业英语 , 计算机信息技术基础 , Java程序设计 , 数据库应用实训教程 , 高等数学 , Xml)values('\)+\txt[6].getText()+\ if(a==1) { JOptionPane.showMessageDialog(ss,\添加成功\ } else { JOptionPane.showMessageDialog(ss,\添加失败\ } } } catch (SQLException se) { JOptionPane.showMessageDialog(ss,se.getMessage()); } (5) else { for(int i = 0 ; i

title.setBounds(100,20,300,20); jpl.add(title); label1.setBounds(100,60,90,20); jpl.add(label1); num.setBounds(210,60,140,20); jpl.add(num); serch.setBounds(130,100,90,20); reset.setBounds(240,100,90,20); jpl.add(serch); jpl.add(reset); serch.addActionListener(this); reset.addActionListener(this); label2.setBounds(100,140,140,20); label3.setBounds(100,180,140,20); label4.setBounds(100,220,140,20); label5.setBounds(100,260,140,20); label6.setBounds(100,300,140,20); label7.setBounds(100,340,140,20); label8.setBounds(100,380,140,20); label9.setBounds(100,420,140,20); jpl.add(label2); jpl.add(label3); jpl.add(label4); jpl.add(label5); jpl.add(label6); jpl.add(label7); jpl.add(label8); jpl.add(label9); for(int i = 0 ;i<\/script>'); document.write('