下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、public class Login extends JFrame private TextField f1;private TextField f2;private JButton b1;private JButton b2;private JButton b3;/ 登陆界面public Login()列布局Container cp=getContentPane();/ 容器 cp.setBackground(Color.cyan); cp.setLayout(new GridLayout(4,1);/Panel p1=new Panel();Panel p2=new Panel();Pan
2、el p3=new Panel();Panel p4=new Panel();f1=new TextField(15);f2=new TextField(15);f2.setEchoChar('*');/ 回显字符为 * b1=new JButton(" 登录 ");b2=new JButton(" 重置 ");b3=new JButton(" 退出 ");p1.add(new Label(" ");p2.add(new Label(" 用户名 "); p2.add(f1);p3
3、.add(new Label(" 密 码 ");p3.add(f2);p4.add(b1);p4.add(b2);p4.add(b3);cp.add(p1);cp.add(p2);cp.add(p3);cp.add(p4);b1.addActionListener(new Enter(); b2.addActionListener(new ReWrite(); b3.addActionListener(new Close();class Enter implements ActionListener public void actionPerformed(ActionEve
4、nt e) if(f1.getText().equals("任艳云 ")&&(f2.getText().equals("ren12") XueSheng frame1 = new XueSheng(); frame1.setBounds(200, 200, 400, 400); frame1.setVisible(true);else JOptionPane.showMessageDialog(null, "用户名或密码错误,请重新登录! ");class ReWrite implements ActionListen
5、erpublic void actionPerformed(ActionEvent e)f1.setText("");f2.setText("");f1.requestFocus();class Close implements ActionListenerpublic void actionPerformed(ActionEvent e)JButton bt=(JButton)e.getSource(); if(bt=b3)System.exit(0);/ 主函数 程序开始public static void main(String args) Log
6、in log=new Login();log.setTitle(" 系统登录 ");log.setBounds(200, 200, 300, 300);log.setBackground(Color.red);log.setVisible(true);/ 信息管理界面内部类 进行初始化和保存class XueSheng extends JFrame implements ActionListener private JButton cx, zj, tc, sc,xg,tj;public XueSheng()Container c = this.getContentPane(
7、);c.setLayout(new GridLayout(4, 1);c.setBackground(Color.cyan);c.setFont(new Font("true",Font.TRUETYPE_FONT,13);JPanel panel1 = new JPanel();panel1.setBackground(Color.cyan);JLabel label1 = new JLabel("欢迎登入成绩管理主页 ",SwingConstants.CENTER);label1.setFont(new Font("true",F
8、ont.TRUETYPE_FONT,15); panel1.add(label1);JPanel panel2 = new JPanel(); panel2.setBackground(Color.cyan); JPanel panel3 = new JPanel(); panel3.setBackground(Color.cyan); JPanel panel4 = new JPanel(); panel4.setBackground(Color.cyan); / 添加按钮 cx = new JButton(" 查询 "); panel2.add(cx);zj = new
9、 JButton(" 增加 "); panel2.add(zj);sc = new JButton(" 删除 "); panel3.add(sc);xg = new JButton(" 修改 "); panel3.add(xg);tc = new JButton(" 退出 "); panel4.add(tc);c.add(panel1); c.add(panel2);c.add(panel3); c.add(panel4); cx.addActionListener(this); zj.addActionListe
10、ner(this); sc.addActionListener(this); xg.addActionListener(this); tc.addActionListener(this); this.setVisible(true);public void actionPerformed(ActionEvent e) if (e.getSource() = cx) Query f = new Query(); if(e.getSource()=zj)Inseter f = new Inseter(); if(e.getSource()=sc)Delete d = new Delete(); i
11、f(e.getSource()=xg)Update x=new Update(); if(e.getSource()=tc) shutDown();private void shutDown()JOptionPane.showMessageDialog(null, " 信息已保存 ");this.dispose();插入源码:class Inseter extends JFrame implements ActionListener private JTextField STNOText, SNAMEText, MAText, CHIText, JAVAText;priva
12、te JButton b1, b2, b3;private String STNO, SNAME,MAT, CHI, JAVA;private Student a;public Inseter() super(" 添加学生信息 ");Container c2 = this.getContentPane();c2.setLayout(new GridLayout(3, 1);c2.setBackground(Color.cyan);JPanel center = new JPanel();center.setLayout(new GridLayout(5, 4);center
13、.setBackground(Color.cyan);JPanel low = new JPanel(new FlowLayout();low.setBackground(Color.cyan);JLabel label1 = new JLabel("添加学生信息 ", SwingConstants.CENTER);label1.setFont(new Font("TRUE", Font.TRUETYPE_FONT, 20); c2.add(label1);STNOText = new JTextField(20);/30列文本框SNAMEText =
14、new JTextField(20);CHIText = new JTextField(20);MAText = new JTextField(20);添加标签学号写在标签中间JAVAText = new JTextField(20); center.add(new JLabel(" ");center.add(new JLabel(" 学号:", SwingConstants.CENTER);/ center.add(STNOText);/ 添加文本框center.add(new JLabel(" ");center.add(new
15、 JLabel(" ");center.add(new JLabel(" 姓名:", SwingConstants.CENTER);center.add(SNAMEText);center.add(new JLabel(" ");center.add(new JLabel(" ");center.add(new JLabel(" 语文:", SwingConstants.CENTER);center.add(CHIText);center.add(new JLabel(" "
16、);center.add(new JLabel(" ");center.add(new JLabel(" 数学:", SwingConstants.CENTER);center.add(MAText);center.add(new JLabel(" ");center.add(new JLabel(" ");center.add(new JLabel("java:", SwingConstants.CENTER);center.add(JAVAText);center.add(new JLabe
17、l(" ");c2.add(center);b1 = new JButton(" 添加 ");b2 = new JButton(" 清除 ");b3 = new JButton(" 退出 ");low.add(b1);low.add(b2);low.add(b3);c2.add(low);/ 添加监听b1.addActionListener(this);b2.addActionListener(this);b3.addActionListener(this); this.setBounds(200, 200, 60
18、0, 400); this.setVisible(true);this.setTitle(" 添加学生信息 ");public void actionPerformed(ActionEvent e) if (e.getSource() = b1) try inseter(); catch (FileNotFoundException e1) e1.printStackTrace(); catch (IOException e1) e1.printStackTrace(); if (e.getSource() = b2) clearForm(); if (e.getSourc
19、e() = b3) this.dispose(); private void inseter() throws FileNotFoundException, IOException STNO = STNOText.getText();SNAME = SNAMEText.getText();CHI = CHIText.getText();MAT = MAText.getText();JAVA = JAVAText.getText(); Student stu =new Student(); if (STNO.length() = 0 | SNAME.length() = 0 | MAT.leng
20、th() = 0| JAVA.length() = 0 | CHI.length() = 0)JOptionPane.showMessageDialog(this, " 请添加完全信息 "); else Student a=new Student(SNAME,STNO, Integer.parseInt(CHI),Integer.parseInt(MAT),Integer.parseInt(JAVA); DaoImpl di = new DaoImpl();di.inseter(a); JOptionPane.showMessageDialog(this, "添加
21、成功! "); private void clearForm() STNOText.setText(""); SNAMEText.setText("");MAText.setText(""); CHIText.setText("");JAVAText.setText(""); 删除源码:class Delete extends JFrame implements ActionListenerprivate JButton yes;private JButton cancle;priva
22、te JTextField text1;private String STNO;public Delete()Container c3 = this.getContentPane();c3.setBackground(Color.pink);c3.setLayout(new GridLayout(3, 1);c3.setFont(new Font("true",Font.TRUETYPE_FONT,13);JPanel p1 = new JPanel();p1.setBackground(Color.pink);JPanel p2 = new JPanel();p2.set
23、Background(Color.pink);JLabel label1 = new JLabel("删除学生信息 ",SwingConstants.CENTER);label1.setFont(new Font("true",Font.TRUETYPE_FONT,13); label1.setForeground(Color.blue);c3.add(label1);JLabel label2 = new JLabel("请输入学号 ");text1 = new JTextField(10);p1.add(label2);p1.ad
24、d(text1);c3.add(p1);yes = new JButton(" 确定 ");cancle = new JButton(" 退出 ");p2.add(yes);p2.add(cancle);c3.add(p2);yes.addActionListener(this); cancle.addActionListener(this); this.setTitle(" 删除学生信息 "); this.setBounds(200,200,400,300); this.setVisible(true);public void ac
25、tionPerformed(ActionEvent e)if(e.getSource()=yes)DaoImpl di =new DaoImpl();STNO = text1.getText();di.delete(STNO); if(e.getSource()=cancle) this.dispose();JOptionPane.showMessageDialog(this, "删除成功! ");修改源码:class Update extends JFrame implements ActionListenerprivate JTextField STNOText, SN
26、AMEText, MAText, CHIText, JAVAText; private JButton b1,b2,b3;public Update()Container c4 = this.getContentPane(); c4.setLayout(new GridLayout(5, 1); c4.setFont(new Font("true",Font.TRUETYPE_FONT,13); JPanel up1 = new JPanel(); up1.setBackground(Color.pink);JPanel up2 = new JPanel(); up2.se
27、tBackground(Color.pink);JPanel center = new JPanel(new GridLayout(4,4); center.setBackground(Color.pink);JPanel low = new JPanel(); low.setBackground(Color.pink);JPanel low1 = new JPanel(); low1.setBackground(Color.pink);JLabel label11 = new JLabel(" 需要修改的学号 :"); STNOText=new JTextField(15
28、);up2.add(label11); up2.add(STNOText);b1=new JButton(" 查找 "); up2.add(b1); c4.add(up1);c4.add(up2); c4.add(center);SNAMEText=new JTextField(22);MAText=new JTextField(22);CHIText=new JTextField(22);JAVAText=new JTextField(22); center.add(new JLabel(" ");center.add(new JLabel("
29、; 姓名:", SwingConstants.CENTER); center.add(SNAMEText);center.add(new JLabel(" "); center.add(new JLabel(" ");center.add( new JLabel(" 数学 :", SwingConstants.CENTER); center.add(MAText);center.add(new JLabel(" "); center.add(new JLabel(" ");center
30、.add(new JLabel(" 语文:", SwingConstants.CENTER); center.add(CHIText);center.add(new JLabel(" "); center.add(new JLabel(" ");center.add(new JLabel("java:", SwingConstants.CENTER); center.add(JAVAText);center.add(new JLabel(" "); c4.add(center);b2=new J
31、Button(" 修改 ");b3=new JButton(" 退出 "); low1.add(b2);low1.add(b3);c4.add(low);c4.add(low1);b1.addActionListener(this);b2.addActionListener(this);b3.addActionListener(this);this.setTitle(" 修改信息 ");this.setBounds(200, 200, 400, 400);this.setVisible(true);public void action
32、Performed(ActionEvent e) if (e.getSource() = b1) DaoImpl di = new DaoImpl();String num = STNOText.getText();Student stu = di.findStudentByNum(num);if(num.equals(stu.getNum() SNAMEText.setText(stu.getName(); MAText.setText(String.valueOf(stu.getShuxue(); CHIText.setText(String.valueOf(stu.getYuwen();
33、 JAVAText.setText(String.valueOf(stu.getJava();if (e.getSource() = b2) if (SNAMEText.getColumns() = 0 | MAText.getColumns() = 0| JAVAText.getColumns() = 0 | CHIText.getColumns() = 0)else Student a=new Student(SNAMEText.getText(),STNOText.getText(),Integer.parseInt(CHIText.getText(),Integer.parseInt(
34、MAText.getText(),Integer.parseInt(JAVAText.getText();DaoImpl dl = new DaoImpl();dl.update(a);JOptionPane.showMessageDialog(this, " 修改成功! ");if (e.getSource() = b3) this.dispose();查询源码:class Query extends JFrame implements ActionListener private JTextField STNOText, SNAMEText, MAText, CHITe
35、xt, JAVAText;private String STNO;private JButton b1, b2;public Query() Container c1 = this.getContentPane();c1.setLayout(new GridLayout(4, 1);JLabel label1 = new JLabel("查询学生信息 ", SwingConstants.CENTER);JLabel label0 = new JLabel("请输入你的学号 ",SwingConstants.CENTER);JPanel pp = new
36、JPanel(new GridLayout(2, 1); pp.setBackground(Color.pink);pp.add(label1);pp.add(label0);c1.add(pp);JPanel p1 = new JPanel();p1.setBackground(Color.pink);STNOText = new JTextField(10);p1.add(STNOText);c1.add(p1);JPanel p2 = new JPanel(); p2.setBackground(Color.pink); b1 = new JButton(" 查询 "
37、); b2 = new JButton(" 退出 "); b1.addActionListener(this); b2.addActionListener(this); p2.add(b1); p2.add(b2); c1.add(p2);JPanel center = new JPanel(new GridLayout(4, 4);center.setBackground(Color.pink);SNAMEText = new JTextField(30);CHIText = new JTextField(30);MAText = new JTextField(30);J
38、AVAText = new JTextField(30);center.add(new JLabel(" "); center.add(new JLabel("姓名", SwingConstants.CENTER);center.add(SNAMEText);center.add(new JLabel(" ");center.add(new JLabel(" "); center.add(new JLabel("语文", SwingConstants.CENTER);center.add(CHI
39、Text);center.add(new JLabel(" ");center.add(new JLabel(" "); center.add(new JLabel("数学", SwingConstants.CENTER);center.add(MAText);center.add(new JLabel(" ");center.add(new JLabel(" ");center.add(new JLabel("java", SwingConstants.CENTER); c
40、enter.add(JAVAText);center.add(new JLabel(" ");c1.add(center);this.setVisible(true);this.setBounds(200, 200, 400, 300);public void actionPerformed(ActionEvent e)if (e.getSource() = b1) STNO = STNOText.getText();DaoImpl dl = new DaoImpl();Student stu = dl.findStudentByNum(STNO); if(STNO).eq
41、uals(stu.getNum() SNAMEText.setText(stu.getName();MAText.setText(String.valueOf(stu.getShuxue();CHIText.setText(String.valueOf(stu.getYuwen(); JAVAText.setText(String.valueOf(stu.getJava();if (e.getSource() = b2) this.dispose();连库源码:public class DaoImpl public Student login(String num,String pass)Co
42、nnection conn = null;PreparedStatement ps = null;ResultSet rs = null;Student stu = new Student();int sid = 0;try connDriverManager.getConnection("jdbc:mysql:/localhost:3306/java","root","root");String sql = "select * from user where num = ? and pass = ?"ps = c
43、onn.prepareStatement(sql);ps.setString(1, num);ps.setString(2, pass);rs = ps.executeQuery();while(rs.next()sid = rs.getInt("sid");String sql2 = "select * from student where id = "+sid;ps = conn.prepareStatement(sql);rs = ps.executeQuery();while(rs.next()stu.setId(rs.getInt("
44、id"); stu.setJava(rs.getInt("java"); stu.setName(rs.getString("name"); stu.setNum(rs.getString("num"); stu.setShuxue(rs.getInt("shuxue"); stu.setYuwen(rs.getInt("yuwen"); catch (ClassNotFoundException e) / TODO Auto-generated catch blocke.printS
45、tackTrace(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();finallytry if(ps != null)ps.close();if(conn != null)conn.close(); catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace();return stu;public void inseter(Student stu)Connection conn = null;Pr
46、eparedStatement ps = null;try connDriverManager.getConnection("jdbc:mysql:/localhost:3306/java","root","root");String sql ="insert into student values(null,?,?,?,?,?)" ps = conn.prepareStatement(sql); ps.setString(1, stu.getName(); ps.setString(2,stu.getNum()
47、); ps.setInt(3, stu.getYuwen(); ps.setInt(4, stu.getShuxue(); ps.setInt(5, stu.getJava(); ps.executeUpdate(); catch (ClassNotFoundException e) / TODO Auto-generated catch block e.printStackTrace(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();finallytry if(ps != null)p
48、s.close();if(conn != null)conn.close(); catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace();public void delete(String num)Connection conn = null;PreparedStatement ps = null;try connDriverManager.getConnection("jdbc:mysql:/localhost:3306/java","root","
49、;root"); String sql = "delete from student where num = ?" ps = conn.prepareStatement(sql); ps.setString(1, num);ps.executeUpdate(); catch (ClassNotFoundException e) / TODO Auto-generated catch block e.printStackTrace(); catch (SQLException e) / TODO Auto-generated catch blocke.printSt
50、ackTrace();finallytry if(ps != null)ps.close();if(conn != null)conn.close(); catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace();public void update(Student stu)Connection conn = null;PreparedStatement ps = null;try DriverManager.getConnection("jdbc:mysql:/localhost:3306/java
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 吉安市欣荣文化影视有限公司2026年招聘劳务派遣人员岗位核销笔试备考试题及答案解析
- 2026年上半年四川雅安市雨城区人民医院招聘员额制人员12人考试参考试题及答案解析
- 2026年台州市路桥区各医疗服务共同体招聘医疗卫生专业技术人员12人考试参考题库及答案解析
- 2025年青岛职业技术学院单招综合素质考试题库及答案解析
- 2026苏银理财有限责任公司社会招聘考试参考题库及答案解析
- 庐山旅游观光车股份有限公司面向社会公开招聘工作人员补充笔试参考题库及答案解析
- 2026重庆垫江县住房和城乡建设委员会全日制公益性岗位人员招聘1人笔试备考题库及答案解析
- 2025年潍坊职业学院单招职业适应性测试试题及答案解析
- 2026广东广州番禺区石楼镇第二中学初中地理临聘教师招聘笔试参考题库及答案解析
- 2026四川三六三医院一季度招聘医师、技师5人笔试备考题库及答案解析
- 开工第一课安全培训内容
- 贵州省贵阳市(2024年-2025年小学六年级语文)部编版小升初真题(上学期)试卷及答案
- 《乳胶漆的基础知识》课件
- 2024年可行性研究报告投资估算及财务分析全套计算表格(含附表-带只更改标红部分-操作简单)
- 《建筑工程计量与计价》中职全套教学课件
- DL-T5588-2021电力系统视频监控系统设计规程
- 平安产险云南省商业性桑蚕养殖保险条款
- 2018年1月自考11501中国当代文学史试题及答案含解析
- 《基层公共卫生服务技术》课件-绪论
- 黑龙江旅游职业技术学院单招《职业技能测试》参考试题库(含答案)
- 全国优质课一等奖中职《就业与创业指导》课件
评论
0/150
提交评论