java编写的学生管理.doc_第1页
java编写的学生管理.doc_第2页
java编写的学生管理.doc_第3页
java编写的学生管理.doc_第4页
java编写的学生管理.doc_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

用户名 :123,密码:abc/-Login类 登录窗体package zhuang;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class Login implements ActionListenerTextField name;TextField password;public Frame f;public static void main( String args)throws Exception Login lg = new Login();lg.createUI();public void createUI()f = new Frame(登录界面);f.add(new Label(请输入您的用户信息:),North); Panel p1 = new Panel();p1.setLayout(new BorderLayout();Panel p11 = new Panel();p11.setLayout(new GridLayout(2,1);p11.add(new Label(用户名:);p11.add(new Label(密 码:);Panel p12 = new Panel();p12.setLayout(new GridLayout(2,1);name = new TextField(10);name.addActionListener(this);password = new TextField(10);password.setEchoChar(*);password.addActionListener(this);p12.add(name);p12.add(password);p1.add(p11,West);p1.add(p12,Center);Panel p2 = new Panel();Button submit = new Button(登录);Button reset = new Button(取消);submit.addActionListener(this);reset.addActionListener(this);p2.add(submit);p2.add(reset);f.add(p1,Center);f.add(p2,South);f.addWindowListener(new WindowAdapter()public void windowClosing(WindowEvent e)System.exit(0);); f.setSize(200,130);f.setLocation(300,200);f.setVisible( true);public void actionPerformed(ActionEvent e) String s = e.getActionCommand();if(s.equals(取消) System.exit(0); if(s.equals(登录) | (e.getSource()=name) | (e.getSource()=password) this.submit();public void submit()String n = name.getText();String psw = password.getText();if(n.equals(123)&psw.equals(abc)f.setVisible(false); trynew xitongFrame(); catch (Exception ex) else JOptionPane.showMessageDialog(null, 帐号或密码错误!, 警告, JOptionPane.ERROR_MESSAGE); /-Student类,主窗体 package zhuang; import javax.swing.*; import java.awt.event.*; import java.awt.*; import java.io.*; import java.sql.*; import zhuang.query; public class Student extends JFrame implements ActionListener private JButton show;private JButton insert; private JButton delete; private JButton edit;private JButton exit; privateJButton query;JTable table;Object data=new Object309;String title=编号,学号,姓名,性别,出生年月,院系名称,英语,数学,JAVA; Connection conn; Statement stat; ResultSet rs; public Student()throws Exception super(学生信息管理系统); JPanel p=new JPanel(); JLabel label=new JLabel(学生信息); show = new JButton(显示全部); insert = new JButton(插入); delete = new JButton(删除); edit = new JButton(修改); query=new JButton(查询); exit=new JButton(退出); this.setSize(750,600); p.add(show);p.add(insert);p.add(edit); p.add(query);p.add(delete);p.add(exit); show.addActionListener(this); insert.addActionListener(this); query.addActionListener(this); edit.addActionListener(this); delete.addActionListener(this); exit.addActionListener(this); table=new JTable(data,title); /table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); JScrollPane pane=new JScrollPane(table); this.add(Center,pane); this.add(label,North); this.add(p,South); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.connection(); this.pack(); public void connection() try Class.forName(sun.jdbc.odbc.JdbcOdbcDriver); String url=jdbc:odbc:students; conn=DriverManager.getConnection(url); stat = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); catch (Exception ex) public void actionPerformed(ActionEvent e) if(e.getSource()=show) Showall(); if (e.getSource()=insert) Insert(); if (e.getSource()=query) Query1(); if (e.getSource()=delete) Delete(); if (e.getSource()=edit) Update(); if(e.getSource()=exit) System.exit(0); public void Showall() try for(int x=0;xdata.length;x+) datax0=null; datax1=null; datax2=null; datax3=null; datax4=null; datax5=null; datax6=null; datax7=null; datax8=null; int i=0; rs=stat.executeQuery(select * from students); while(rs.next() datai0=rs.getString(1); datai1=rs.getString(2); datai2=rs.getString(3); datai3=rs.getString(4); datai4=rs.getString(5); datai5=rs.getString(6); datai6=rs.getInt(7); datai7=rs.getInt(8); datai8=rs.getInt(9); i=i+1; this.repaint(); catch (SQLException ex) private void Insert() try JTextField t=new JTextField16; t0=new JTextField(输入学号:); t0.setEditable(false); t1=new JTextField(); t2=new JTextField(输入姓名:); t2.setEditable(false); t3=new JTextField(); t4=new JTextField(输入性别:); t4.setEditable(false); t5=new JTextField(); t6=new JTextField(出生年月:); t6.setEditable(false); t7=new JTextField(); t8=new JTextField(院系名称:); t8.setEditable(false); t9=new JTextField(); t10=new JTextField(英语成绩 :); t10.setEditable(false); t11=new JTextField(); t12=new JTextField( 数学成绩:); t12.setEditable(false); t13=new JTextField(); t14=new JTextField(JAVA成绩:); t14.setEditable(false); t15=new JTextField(); String but=确定,取消; int go=JOptionPane.showOptionDialog(null,t,插入信息,JOptionPane.YES_OPTION,JOptionPane.INFORMATION_MESSAGE,null,but,but0); if(go=0) try String sno=new String(t1.getText(); String name=new String(t3.getText(); String sex=new String(t5.getText(); String birthday=new String(t7.getText(); String department=new String(t9.getText(); int english=Integer.parseInt(t11.getText(); int manth=Integer.parseInt(t13.getText(); int java=Integer.parseInt(t15.getText(); connection(); stat.executeUpdate(insert into students (sno,name,sex,birthday,department,english,manth,java) values (+sno+,+name+,+sex+,+birthday+,+department+,+english+,+manth+,+java+); JOptionPane.showMessageDialog(null,数据插入成功!); this.Showall(); catch(Exception ee) catch (Exception ex) public void Query1() tryquery q=new query();catch (Exception ex) public void Delete() try int row=table.getSelectedRow(); stat.executeUpdate(delete from students where sno=+datarow1+); JOptionPane.showMessageDialog(null,数据删除成功); this.Showall(); catch (SQLException ex) public void Update() try int row=table.getSelectedRow(); JTextField t=new JTextField16; t0=new JTextField(输入学号:); t0.setEditable(false); t1=new JTextField(); t2=new JTextField(输入姓名:); t2.setEditable(false); t3=new JTextField(); t4=new JTextField(输入性别:); t4.setEditable(false); t5=new JTextField(); t6=new JTextField(出生年月:); t6.setEditable(false); t7=new JTextField(); t8=new JTextField(院系名称:); t8.setEditable(false); t9=new JTextField(); t10=new JTextField(英语成绩 :); t10.setEditable(false); t11=new JTextField(); t12=new JTextField(数学成绩 :); t12.setEditable(false); t13=new JTextField(); t14=new JTextField(JAVA成绩:); t14.setEditable(false); t15=new JTextField(); String but=确定,取消; int go=JOptionPane.showOptionDialog(null,t,请输入该生的新信息:, JOptionPane.YES_OPTION,JOptionPane.INFORMATION_MESSAGE,null,but,but0); if(go=0) try String sno=new String(t1.getText(); String name=new String(t3.getText(); String sex=new String(t5.getText(); String birthday=new String(t7.getText(); String department=new String(t9.getText(); int english=Integer.parseInt(t11.getText(); int manth=Integer.parseInt(t13.getText(); int java=Integer.parseInt(t15.getText(); connection(); stat.executeUpdate(update students +set sno=+sno+,+name=+name+,+sex=+sex+,+birthday=+birthday+,+department=+department+,+english=+english+,+manth=+manth+,+java=+java+where sno=+datarow1+); JOptionPane.showMessageDialog(null,数据修改成功!); this.Showall(); catch(Exception ee) catch (Exception ex) /-query类,按名查询package zhuang;import javax.swing.*;import java.awt.event.*;import java.awt.*;import java.io.*;import java.sql.*;public class query extends JFrame implements ActionListener JButton but=new JButton(查询);JButton ret=new JButton(返回);TextField text;String sname;Object da=new Object3010;String ti=编号,学号,姓名,性别,出生年月,院系名称,数学,英语,计算机,总分;Connection conn; Statement stat; ResultSet rs;public query()throws Exception super(查询结果); JPanel p=new JPanel(); but.addActionListener(this); ret.addActionListener(this); this.setVisible(true); /this.setSize(400,400); JTable table; JLabel a=new JLabel(学生信息:); JLabel b=new JLabel(请输入姓名:); TextField text=new TextField(); table=new JTable(da,ti);JScrollPane pane=new JScrollPane(table); p.add(b); p.add(text); p.add(but); p.add(ret); this.add(p,South); this.add(Center,pane); this.add(a,North); this.pack(); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.connection(); public void connection() try Class.forName(sun.jdbc.odbc.Jd

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论