学生选课系统(连接Mysql数据库)(18页).doc
《学生选课系统(连接Mysql数据库)(18页).doc》由会员分享,可在线阅读,更多相关《学生选课系统(连接Mysql数据库)(18页).doc(18页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、-/*JDBC连接数据库*/package immoc4.bao;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class JDBC private static final String URL = jdbc:mysql:/localhost:3306/a?characterEncoding=utf8;private static final Stri
2、ng USER = root;private static final String PASSWORD = 995923;private static Connection conn = null;static try Class.forName(com.mysql.jdbc.Driver);conn = DriverManager.getConnection(URL, USER, PASSWORD); catch (ClassNotFoundException e) e.printStackTrace(); catch (SQLException e) e.printStackTrace()
3、;public static Connection getConnection() return conn;/*登录界面*/package immoc4.bao;import java.awt.FlowLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.SQLException;import java.util.Scanner;import javax.swing.JButton;import javax.swing.JFrame;import javax.s
4、wing.JLabel;import javax.swing.JTextField;public class View extends JFramestatic GongNeng gn = new GongNeng();static Student s = new Student();static JTextField text1;static JTextField text2;static JButton button; public void denglu()setLayout(new FlowLayout();add(new JLabel(用户id:);text1 = new JText
5、Field(20);add(text1);add(new JLabel(密码:);text2 = new JTextField(20);add(text2);button = new JButton(登录);add(button); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); /关闭窗口 public static void main(String args)View dl = new View();dl.setBounds(300, 300, 300, 200);dl.setTitle(学生选课管理系统)
6、;dl.denglu(); button.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) / TODO Auto-generated method stub dl.dispose(); s.setStudent_id(Integer.parseInt(text1.getText(); s.setStudent_code(text2.getText(); try gn.correspond(s); catch (SQLException e1) / TODO Auto-genera
7、ted catch blocke1.printStackTrace(); ); /*主界面*/package immoc4.bao;import javax.swing.*;import immoc4.bao.Course;import java.awt.*;import java.awt.event.*;import java.sql.SQLException;public class Card extends JFrame /* * JFrame的布局管理器是BorderLayout */Course g = new Course();GongNeng gn = new GongNeng(
8、); JPanel p;/位于中心区域的面板 JButton b1,b2,b3,b4;/位于北部区域的四个按钮 JButton add; JButton delete; JButton update; JButton query; JLabel add_id,add_name,add_teacher_name; JLabel delete_id; JLabel update_id,update_name,update_teacher_name; JLabel query_id; JLabel query_show; JTextField text_add_id,text_add_name,te
9、xt_add_teacher_name; JTextField text_delete_id; JTextField text_update_id,text_update_name,text_update_teacher_name; JTextField text_query_id; JTextArea area_query_show; CardLayout c;/设置面板p的布局 Card() super(); this.setVisible(true); this.setBounds(400,300,400,300); p = new JPanel();/实例化p c = new Card
10、Layout();/实例化c p.setLayout(c);/设置面板p的布局为c,等价于p = new JPanel(c); /实例化4个按钮和标签 b1 = new JButton(添加课程); b2 = new JButton(删除课程); b3 = new JButton(修改课程); b4 = new JButton(查询课程); /实例化4个子面板并设定相应背景颜色 JPanel p1 = new JPanel(); JPanel p2 = new JPanel(); JPanel p3 = new JPanel(); JPanel p4 = new JPanel(); / p1.
11、setLayout( p1.setBackground(Color.green); p2.setBackground(Color.pink); p3.setBackground(Color.orange); p4.setBackground(Color.lightGray); /把上面4个面板添加到中心面板p中,并把4个面板分别用编号为1,2,3,4代替 p.add(p1,1); p.add(p2,2); p.add(p3,3); p.add(p4,4); /实例化位于南部区域的面板,并添加4个按钮 JPanel pnorth = new JPanel(); pnorth.add(b1); p
12、north.add(b2); pnorth.add(b3); pnorth.add(b4); /把p,psourth分别添加到本JFrame的中心区域和南部区域 this.add(p);/等价于this.add(p,BorderLayout.CENTER); 因为默认是把组件添加到中部 this.add(pnorth,BorderLayout.NORTH); / 添加课程 add_id = new JLabel(课程号); text_add_id = new JTextField(30); add_name = new JLabel(课程名); text_add_name = new JTex
13、tField(30); add_teacher_name = new JLabel(教师名); text_add_teacher_name = new JTextField(30); add = new JButton(添加); /为按钮b1添加监听器,当被按下时显示面板p中的前一个子面板 b1.addActionListener(new ActionListener() Override public void actionPerformed(ActionEvent e) / TODO Auto-generated method stub c.show(p,1);/显示p中的上一个面板 p1
14、.add(add_id); p1.add(text_add_id); p1.add(add_name); p1.add(text_add_name); p1.add(add_teacher_name); p1.add(text_add_teacher_name); p1.add(add); setVisible(true); ); add.addActionListener(new ActionListener()Overridepublic void actionPerformed(ActionEvent e) / TODO Auto-generated method stubg.setId
15、(Integer.parseInt(text_add_id.getText();g.setName(text_add_name.getText();g.setTeacher_name(text_add_teacher_name.getText();try gn.addcourse(g); catch (Exception e1) / TODO Auto-generated catch blocke1.printStackTrace(); ); /删除课程 delete_id = new JLabel(课程号); text_delete_id = new JTextField(20); dele
16、te = new JButton(删除); /为按钮b2添加监听器,当被按下时显示面板p中的第2个子面板 b2.addActionListener(new ActionListener() Override public void actionPerformed(ActionEvent e) / TODO Auto-generated method stub c.show(p, 2);/显示p中代号为2的面板 p2.add(delete_id); p2.add(text_delete_id) ; p2.add(delete); setVisible(true); ); delete.addAc
17、tionListener(new ActionListener()Overridepublic void actionPerformed(ActionEvent e) / TODO Auto-generated method stub int id = Integer.parseInt(text_delete_id.getText();try gn.delCourse(id); catch (SQLException e1) / TODO Auto-generated catch blocke1.printStackTrace();); / 修改课程 update_id = new JLabe
18、l(课程号); text_update_id = new JTextField(30); update_name = new JLabel(课程名); text_update_name = new JTextField(30); update_teacher_name = new JLabel(教师名); text_update_teacher_name = new JTextField(30); update = new JButton(修改); /以下类推 b3.addActionListener(new ActionListener() Override public void acti
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 学生 选课 系统 连接 Mysql 数据库 18
限制150内