java实验报告 - - 129074(8)

2019-06-05 11:14

box4.add(录入); Box boxH=Box.createVerticalBox();//竖放box boxH.add(box1); boxH.add(box2); boxH.add(box3); boxH.add(box4); boxH.add(Box.createVerticalGlue()); JPanel messPanel=new JPanel(); messPanel.add(boxH); setLayout(new BorderLayout()); add(messPanel,BorderLayout.CENTER); validate(); }

public void actionPerformed(ActionEvent c){ Object obj=c.getSource(); if(obj==录入){ if(学号.getText().equals(\)||姓名.getText().equals(\)||系别.getText().equals(\)){ JOptionPane.showMessageDialog(this,\学生信息请填满再录入!\ ); } Statement stmt=null; ResultSet rs1=null; String sql,sql1; sql1=\+学号.getText()+\; sql=\+学号.getText()+\+姓名.getText()+\+系别.getText()+\; try{ Connection dbConn1=CONN(); stmt=(Statement)dbConn1.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); rs1=stmt.executeQuery(sql1); if(rs1.next()){JOptionPane.showMessageDialog(this,\该学号以存在,无法添加\);} else{ stmt.executeUpdate(sql); JOptionPane.showMessageDialog(this,\添加成功\); } rs1.close(); stmt.close(); } catch(SQLException e){ System.out.print(\+e.getMessage()); } }}}

//查询学生

package search_10_3; import java.awt.*;

import java.awt.event.*; import java.sql.*;

import javax.swing.*;

public class Selstu extends JPanel implements ActionListener{ /** * */ private static final long serialVersionUID = 1L; JTextField 学号,姓名,系别; JButton 查找; JTextField 课号,课名; JButton 查找1; JTextField 课号1,学号1,成绩; JButton 查找2; public Selstu (){

学号=new JTextField(12); 姓名=new JTextField(12); 系别=new JTextField(12); 课号=new JTextField(12); 课名=new JTextField(12); 课号1=new JTextField(12); 学号1=new JTextField(12); 成绩=new JTextField(12);

查找=new JButton(\查找学生信息\); 查找1=new JButton(\查找课程信息\); 查找2=new JButton(\查找选课信息\);

Box box1=Box.createHorizontalBox();//横放box Box box2=Box.createHorizontalBox(); Box box4=Box.createHorizontalBox(); Box box5=Box.createHorizontalBox(); Box box6=Box.createHorizontalBox(); Box box7=Box.createHorizontalBox();

box1.add(new JLabel(\学号:\,JLabel.CENTER)); box1.add(学号);

box1.add(new JLabel(\姓名:\,JLabel.CENTER)); box1.add(姓名);

box1.add(new JLabel(\系别:\,JLabel.CENTER)); box1.add(系别); box2.add(查找);

box4.add(new JLabel(\课号:\,JLabel.CENTER)); box4.add(课号);

box4.add(new JLabel(\课名:\,JLabel.CENTER)); box4.add(课名); box6.add(查找1);

box5.add(new JLabel(\课号:\,JLabel.CENTER)); box5.add(课号1);

box5.add(new JLabel(\学号:\,JLabel.CENTER)); box5.add(学号1);

box5.add(new JLabel(\成绩:\,JLabel.CENTER)); box5.add(成绩); box7.add(查找2);

Box boxH1=Box.createVerticalBox();//竖放box boxH1.add(box1); boxH1.add(box2);

boxH1.add(Box.createVerticalGlue());

Box boxH2=Box.createVerticalBox();//竖放box boxH2.add(box4); boxH2.add(box6);

boxH2.add(Box.createVerticalGlue());

Box boxH3=Box.createVerticalBox();//竖放box boxH3.add(box5); boxH3.add(box7);

boxH3.add(Box.createVerticalGlue()); 查找.addActionListener(this); 查找1.addActionListener(this); 查找2.addActionListener(this); JPanel messPanel=new JPanel(); JPanel picPanel=new JPanel(); JPanel threePanel=new JPanel(); messPanel.add(boxH1); picPanel.add(boxH2); threePanel.add(boxH3);

setLayout(new BorderLayout());

JSplitPane splitV=new JSplitPane(JSplitPane.VERTICAL_SPLIT,messPanel,picPanel);//分割 add(splitV,BorderLayout.CENTER);

JSplitPane splitV1=new JSplitPane(JSplitPane.VERTICAL_SPLIT,splitV,threePanel);//分割

add(splitV1,BorderLayout.CENTER); validate(); } @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub } }

//更新学生

package search_10_3; import java.awt.*;

import java.awt.event.*; import java.sql.*; import javax.swing.*;

public class Updatastu extends JPanel implements ActionListener{ String save=null; JTextField 学号1,学号,姓名,系别; JButton 修改,查找;

public Updatastu(){ try {UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());} catch(Exception e){System.err.println(\不能设置外观: \+e);} 学号1=new JTextField(12); 学号=new JTextField(12); 姓名=new JTextField(12); 系别=new JTextField(12); 修改=new JButton(\修改\); 查找=new JButton(\查找\); Box box1=Box.createHorizontalBox();//横放box Box box2=Box.createHorizontalBox(); Box box3=Box.createHorizontalBox(); Box box4=Box.createHorizontalBox(); Box box5=Box.createHorizontalBox(); box1.add(new JLabel(\学号:\,JLabel.CENTER)); box1.add(学号); box2.add(new JLabel(\姓名:\,JLabel.CENTER)); box2.add(姓名); box3.add(new JLabel(\系别:\,JLabel.CENTER)); box3.add(系别); box4.add(修改); box5.add(new JLabel(\学号:\,JLabel.CENTER)); box5.add(学号1); box5.add(查找); 修改.addActionListener(this); 查找.addActionListener(this); Box boxH=Box.createVerticalBox();//竖放box boxH.add(box1); boxH.add(box2); boxH.add(box3); boxH.add(box4); boxH.add(Box.createVerticalGlue()); JPanel picPanel=new JPanel(); JPanel messPanel=new JPanel(); messPanel.add(box5); picPanel.add(boxH); setLayout(new BorderLayout()); JSplitPane splitV=new JSplitPane(JSplitPane.VERTICAL_SPLIT,messPanel,picPanel);//分割

add(splitV,BorderLayout.CENTER); validate(); }

public void actionPerformed(ActionEvent e){ Object obj=e.getSource(); Statement stmt=null; ResultSet rs=null,rs1=null;

String sql=null,sql1=null,sqlSC; if(obj==查找){if(学号1.getText().equals(\))JOptionPane.showMessageDialog(this,\请填写查询的学号!\ ); else{ sql1=\+学号1.getText()+\; try{ Connection dbConn1=CONN(); stmt=(Statement)dbConn1.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); rs1=stmt.executeQuery(sql1); if(rs1.next()){学号.setText(rs1.getString(\).trim()); 姓名.setText(rs1.getString(\).trim()); 系别.setText(rs1.getString(\).trim()); save=学号1.getText(); } else{JOptionPane.showMessageDialog(this,\没有这个学号的学生\ );} stmt.close(); rs1.close(); }catch(SQLException e1){ System.out.print(\+e1.getMessage()); } } } else{ if(obj==修改){if(save==null){JOptionPane.showMessageDialog(this,\还没查找需要修改的学生\ );} else{ if(学号.getText().equals(\)||姓名.getText().equals(\)||系别.getText().equals(\)){ JOptionPane.showMessageDialog(this,\学生信息填满才能修改!\ ); } else{sql=\+学号.getText()+\+姓名.getText()+\+系别.getText()+\+\+save+\; if(save.trim().equals(学号.getText().trim())){ try{ Connection dbConn1=CONN(); stmt=(Statement)dbConn1.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); stmt.executeUpdate(sql); save=null; JOptionPane.showMessageDialog(this,\修改完成\ ); 学号.setText(\); 姓名.setText(\); 系别.setText(\); stmt.close(); }catch(SQLException e1){ System.out.print(\+e1.getMessage()); } } else{sql1=\+学号.getText()+\; try{ Connection dbConn1=CONN();

stmt=(Statement)dbConn1.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); rs1=stmt.executeQuery(sql1); if(rs1.next()){ JOptionPane.showMessageDialog(this,\已存在此学号学生\ ); } else{ sqlSC=\+学号.getText()+\+save+\; stmt.executeUpdate(sql); stmt.executeUpdate(sqlSC); save=null; JOptionPane.showMessageDialog(null,\修改完成\ ); 学号.setText(\); 姓名.setText(\); 系别.setText(\);} stmt.close(); rs1.close(); }catch(SQLException e1){ System.out.print(\+e1.getMessage()); } } }}}} }

//连接数据库方法

public static Connection CONN(){ String driverName = \; //加载JDBC驱动 String dbURL = \; //连接服务器和数据库test String userName = \; //默认用户名 String userPwd = \; //密码 Connection dbConn=null; try { Class.forName(driverName); dbConn = DriverManager.getConnection(dbURL, userName, userPwd); System.out.println(\); //如果连接成功 控制台输出Connection Successful! } catch (Exception e) { e.printStackTrace(); } return dbConn; } }

//删除学生

package search_10_3;

import java.awt.*;

import java.awt.event.*; import java.sql.*; import javax.swing.*;

public class Delstu extends JPanel implements ActionListener{ String save=null;

JTextField 学号1,学号,姓名,系别; JButton 删除,查找;

public Delstu(){

try {UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());} catch(Exception e){System.err.println(\不能设置外观: \+e);}


java实验报告 - - 129074(8).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:三网融合:广电网的宏观战略思考

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: