版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、package com.lb.view;import java.awt.*;import java.awt.event.*;import javax.swing.*;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.
2、setLayout(new GridLayout(4,1);/四行一列布局Panel p1=new Panel();Panel p2=new Panel();Panel 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(ne
3、w Label(" ");p2.add(new Label("用户名");p2.add(f1);p3.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 Ent
4、er implements ActionListenerpublic void actionPerformed(ActionEvent 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, &q
5、uot;用户名或密码错误,请重新登录!");class ReWrite implements ActionListenerpublic 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)Sy
6、stem.exit(0);/主函数 程序开始public static void main(String args) Login 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, s
7、c,xg,tj;public XueSheng() Container c = this.getContentPane();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("欢迎登入成绩管理主页",SwingC
8、onstants.CENTER);label1.setFont(new Font("true",Font.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
9、JButton("查询");panel2.add(cx);zj = new 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.addActionL
10、istener(this);zj.addActionListener(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()=s
11、c) Delete d = new Delete(); if(e.getSource()=xg) Update x=new Update(); if(e.getSource()=tc)shutDown();private void shutDown()JOptionPane.showMessageDialog(null, "信息已保存");this.dispose();插入源码:package com.lb.view;import java.awt.Color;import java.awt.Container;import java.awt.FlowLayout;impo
12、rt java.awt.Font;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.FileNotFoundException;import java.io.IOException;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import java
13、x.swing.JPanel;import javax.swing.JTextField;import javax.swing.SwingConstants;import com.lb.bean.Student;import com.lb.dao.DaoImpl;class Inseter extends JFrame implements ActionListener private JTextField STNOText, SNAMEText, MAText, CHIText, JAVAText;private JButton b1, b2, b3;private String STNO,
14、 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.setBackground(Color.cyan);JPanel low = new
15、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 = new JTextField(20);CHIText = new JTextField(20
16、);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 JLabel(" ");center.add(new JLabel("
17、;姓名:", 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(" ");center.add(new JLabel(" ");center.add(ne
18、w 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 JLabel(" ");c2.add(center);b1 = new JButton(&quo
19、t;添加");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, 600, 400);this.setVisible(true);this.setTitle("添加学生信息&quo
20、t;);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.getSource() = b3) this.dispose();private void inseter() throws FileNotFou
21、ndException, 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.length() = 0 | JAVA.length() = 0 | CHI.length() = 0)JOptionPane.showMess
22、ageDialog(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, "添加成功!");private void clearForm() STNOText.setText("");SNAMET
23、ext.setText("");MAText.setText("");CHIText.setText("");JAVAText.setText("");删除源码:package com.lb.view;import java.awt.Color;import java.awt.Container;import java.awt.Font;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionL
24、istener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.JTextField;import javax.swing.SwingConstants;import com.lb.dao.DaoImpl;class
25、Delete extends JFrame implements ActionListenerprivate JButton yes;private JButton cancle;private 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
26、_FONT,13);JPanel p1 = new JPanel();p1.setBackground(Color.pink);JPanel p2 = new JPanel();p2.setBackground(Color.pink);JLabel label1 = new JLabel("删除学生信息",SwingConstants.CENTER);label1.setFont(new Font("true",Font.TRUETYPE_FONT,13);label1.setForeground(Color.blue);c3.add(label1);J
27、Label label2 = new JLabel("请输入学号");text1 = new JTextField(10);p1.add(label2);p1.add(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("
28、删除学生信息");this.setBounds(200,200,400,300);this.setVisible(true); public void actionPerformed(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, "删除成功!"); 修改源码:pac
29、kage com.lb.view;import java.awt.Color;import java.awt.Container;import java.awt.Font;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import
30、 javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.SwingConstants;import com.lb.bean.Student;import com.lb.dao.DaoImpl;class Update extends JFrame implements ActionListenerprivate JTextField STNOText, SNAMEText, MAText, CHIText, JAVAText;private JButton b1,b2,b3;public Update()Cont
31、ainer 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.setBackground(Color.pink);JPanel center = new JPanel(new GridLayout(4,4);center.setBack
32、ground(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);up2.add(label11);up2.add(STNOText);b1=new JButton("查找");up2.add(b1);c4.add(up1)
33、;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("姓名:", SwingConstants.CENTER);center.add(SNAMEText);center.add(new JLabel(" ");cent
34、er.add(new JLabel(" ");center.add( new JLabel("数学:", SwingConstants.CENTER);center.add(MAText);center.add(new JLabel(" ");center.add(new JLabel(" ");center.add(new JLabel("语文:", SwingConstants.CENTER);center.add(CHIText);center.add(new JLabel("
35、");center.add(new JLabel(" ");center.add(new JLabel("java:", SwingConstants.CENTER);center.add(JAVAText);center.add(new JLabel(" ");c4.add(center);b2=new JButton("修改");b3=new JButton("退出");low1.add(b2);low1.add(b3);c4.add(low);c4.add(low1);b1.ad
36、dActionListener(this);b2.addActionListener(this);b3.addActionListener(this);this.setTitle("修改信息");this.setBounds(200, 200, 400, 400);this.setVisible(true);public void actionPerformed(ActionEvent e) if (e.getSource() = b1) DaoImpl di = new DaoImpl();String num = STNOText.getText();Student s
37、tu = di.findStudentByNum(num); if(num.equals(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) if (SNAMEText.getColumns() = 0 | MAText.getColumn
38、s() = 0| JAVAText.getColumns() = 0 | CHIText.getColumns() = 0)else Student a=new Student(SNAMEText.getText(),STNOText.getText(),Integer.parseInt(CHIText.getText(),Integer.parseInt(MAText.getText(),Integer.parseInt(JAVAText.getText();DaoImpl dl = new DaoImpl();dl.update(a);JOptionPane.showMessageDial
39、og(this, "修改成功!");if (e.getSource() = b3) this.dispose();查询源码:package com.lb.view;import java.awt.Color;import java.awt.Container;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import ja
40、vax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.SwingConstants;import com.lb.bean.Student;import com.lb.dao.DaoImpl;class Query extends JFrame implements ActionListener private JTextField STNOText, SNAMEText, MAText, CHIText,
41、 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 JPane
42、l(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("查询");b2 = new
43、 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);JAVAText = new JTex
44、tField(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(CHIText);center.add(new
45、 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);center.add(JAVAText);ce
46、nter.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).equals(stu.getNum()SNAMET
47、ext.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();连库源码:package com.lb.dao;import java.sql.Connection;import java.sql.DriverManager;import java.sql.
48、PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import java.util.List;import com.lb.bean.Student;public class DaoImpl public Student login(String num,String pass)Connection conn = null;PreparedStatement ps = null;ResultSet rs = null;Student stu = n
49、ew Student();int sid = 0;try Class.forName("com.mysql.jdbc.Driver");conn = DriverManager.getConnection("jdbc:mysql:/localhost:3306/java","root","root");String sql = "select * from user where num = ? and pass = ?"ps = conn.prepareStatement(sql);ps.set
50、String(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("id");stu.setJava(rs.getInt(
51、"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.printStackTrace(); catch (SQLException e) /
52、 TODO Auto-generated catch blocke.printStackTrace();finallytry if(ps != null)ps.close();if(conn != null)conn.close(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();return stu;public void inseter(Student stu)Connection conn = null;PreparedStatement ps = null;try Class.fo
53、rName("com.mysql.jdbc.Driver");conn = DriverManager.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() );ps.setInt(3, stu.getYuwen();ps.setInt(4, stu.getShuxue();ps.setInt(5, stu.getJava();ps.execute
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 古建筑工程监理管理规划方案
- 金太阳河南省南阳地区2025-2026学年高一上学期12月阶段考试卷语文(26-176A)(含答案)
- 六年级音乐教学课件设计方案
- 园林景观工程放线测量方案
- 医院感染控制管理规范及执行标准
- 在线教育平台课程管理系统
- 汽车维修项目环保影响评估表模板
- 航拍无人机使用及照片拼接软件教程
- 情报信息收集与分析操作流程说明
- 会计初级职称真题题库及参考答案
- 四川省2025年高职单招职业技能综合测试(中职类)计算机类试卷(含答案解析)
- 2025至2030中国网球行业市场发展分析与发展趋势及投资风险报告
- 袜业生产质量管理工作规范
- DB-T29-317-2024 雪道施工技术规程
- 合同审查流程与审批标准化手册
- 16.2 整式的乘法(第3课时 多项式乘多项式)教学设计
- 心梗检测与预防知识培训课件
- 河北省职业院校技能大赛中职组法律实务赛项参考试题(附答案)
- 幼儿园STEAM教育评价体系-洞察与解读
- 山东建筑大学土木工程材料期末考试复习题及参考答案
- 排风工程安装方案(3篇)
评论
0/150
提交评论