}
public void actionPerformed(ActionEvent ee) { String s1, s2, s3, s4, s5, insert1, recode, name, date, number; int m1, m2, math, english; s1 = input1.getText(); s2 = input2.getText(); s3 = input3.getText(); s4 = input4.getText(); s5 = input5.getText(); number = s1; name = s2; date = s3; m1 = Integer.parseInt(s4); math = m1; m2 = Integer.parseInt(s5); english = m2; try { Class.forName(\ } catch (ClassNotFoundException eee) { System.out.println(\ } try { con = DriverManager.getConnection(\ sql = con.createStatement(); recode = \ + \ insert1 = \ALUES \ sql.executeUpdate(insert1); show.setText(\你插入了:\ show.append(\学号:\ :\ 出生:\ + \数学 \英语 \ show.append(\ } catch (SQLException e) { System.out.println(e); JOptionPane.showMessageDialog(this, \你输入的学号已存在,请核对重新输入!\ } } }
6.2 显示模块
显示模块将输出所有学生的主要信息;
主要代码为:class chuangkou extends JFrame implements ActionListener { JFrame frame = new JFrame(\选择窗口\ JPanel imagePanel; ImageIcon bg;
Button button1, button2, button3, button4, button5, button6; Box box; Label label; Panel p1;
chuangkou() { Toolkit kit = Toolkit.getDefaultToolkit(); Image img = kit.getImage(\ frame.setIconImage(img); p1 = new Panel(); label = new Label(\欢迎使用成绩管理系统\ label.setFont(new Font(\隶书\ label.setBackground(Color.green); p1.add(label); button1 = new Button(\添加\ button2 = new Button(\删除\ button3 = new Button(\修改\ button4 = new Button(\查询\ button5 = new Button(\返回\ button6 = new Button(\退出\ box = Box.createHorizontalBox(); box.add(button1); box.add(Box.createHorizontalStrut(8)); box.add(button2); box.add(Box.createHorizontalStrut(8)); box.add(button3); box.add(Box.createHorizontalStrut(8)); box.add(button4); box.add(Box.createHorizontalStrut(8)); box.add(button5); box.add(Box.createHorizontalStrut(8)); box.add(button6);
态
}
button1.addActionListener(this); button2.addActionListener(this); button3.addActionListener(this); button4.addActionListener(this); button5.addActionListener(this); button6.addActionListener(this);
addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { dispose(); } });
bg = new ImageIcon(\JLabel label = new JLabel(bg);
label.setBounds(0, 0, bg.getIconWidth(), bg.getIconHeight()); imagePanel = (JPanel) frame.getContentPane(); imagePanel.setOpaque(false);
imagePanel.setLayout(new FlowLayout()); imagePanel.add(p1, BorderLayout.NORTH); imagePanel.add(box, BorderLayout.CENTER);
frame.getLayeredPane().setLayout(null);
frame.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置关闭后状frame.setSize(bg.getIconWidth(), bg.getIconHeight()); frame.setBounds(200, 200, 500, 300);
frame.setResizable(false);//设置窗口大小不可改变 frame.setVisible(true); validate();
public void actionPerformed(ActionEvent e) { if (e.getSource() == button6) { System.exit(0); } if (e.getSource() == button1) { new charu(); } if (e.getSource() == button2) { new shanchu(); } if (e.getSource() == button3) {
}
}
new xiugai(); }
if (e.getSource() == button4) { new chaxun(); }
if (e.getSource() == button5) { new denglu(); frame.dispose(); } else { }
6.3 修改模块
首先由用户输入要修改的学生的成绩
主要代码:class xiugai extends JFrame implements ActionListener { JFrame frame = new JFrame(\修改成绩\ JPanel imagePanel; ImageIcon bg; Button xiug;
TextField input1, input2, input3; TextArea show;
Box box1, box2, box3; Panel p1, p2; int k, s1, j;
Connection con; Statement sql; int sum = 0; ResultSet rs;
xiugai() { Toolkit kit = Toolkit.getDefaultToolkit(); Image img = kit.getImage(\ frame.setIconImage(img); p1 = new Panel(); p2 = new Panel(); xiug = new Button(\修改\
input1 = new TextField(10); input2 = new TextField(10); input3 = new TextField(10); show = new TextArea(6, 43); Font f=new Font(\宋体\ Label l1=new Label(\输入学号\ l1.setFont(f); l1.setForeground(Color.blue); p1.add(l1); p1.add(new Label(\学号:\ p1.add(input1); box1 = Box.createVerticalBox(); box1.add(Box.createVerticalStrut(8)); box1.add(new Label(\数学:\ box1.add(Box.createVerticalStrut(8)); box1.add(new Label(\英语:\ box2 = Box.createVerticalBox(); box2.add(input2); box2.add(Box.createVerticalStrut(8)); box2.add(input3); box3 = Box.createHorizontalBox(); box3.add(box1); box3.add(Box.createHorizontalStrut(1)); box3.add(box2); Label l2=new Label(\输入成绩\ l2.setFont(f); l2.setForeground(Color.blue); p2.add(l2); p2.add(box3); xiug.addActionListener(this); show.setEditable(false); bg = new ImageIcon(\ JLabel label = new JLabel(bg); label.setBounds(0, 0, bg.getIconWidth(), bg.getIconHeight()); imagePanel = (JPanel) frame.getContentPane(); imagePanel.setOpaque(false); imagePanel.setLayout(new FlowLayout()); imagePanel.add(p1); imagePanel.add(p2);