⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 editscore.java~5~

📁 java语言写的
💻 JAVA~5~
字号:
package scoremis;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.table.*;import java.sql.*;import java.util.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2007</p> * <p>Company: </p> * @于二坤 * @version 1.0 */public class EditScore extends JFrame{  String kc,bj,xq;  JPanel p=new JPanel();  JLabel l1=new JLabel("课程:");  JComboBox course=new JComboBox();  JLabel l2=new JLabel("班级:");  JComboBox tgreade=new JComboBox();  JLabel l3=new JLabel("学期:");  JComboBox term=new JComboBox();  JButton sure=new JButton("查询");  JButton xgai=new JButton("修改");  JButton tijiao=new JButton("提交");  ResultSet rs=null;  Vector tempvector=new Vector(1,1);  DefaultTableModel model=new DefaultTableModel();  JTable dbtable=new JTable(model);  JScrollPane jScrollPane1=new JScrollPane(dbtable);  String tname,psd,sql="";  public EditScore(String name,String psd) {    try{      tname=name;      this.psd=psd;      jbInit();    } catch(Exception exception) {exception.printStackTrace();}  }  private void jbInit() throws Exception {  //添加各组件    p.add(l1);p.add(course);p.add(l2);p.add(tgreade);p.add(l3);p.add(term);    p.add(sure);p.add(xgai);p.add(tijiao);    add(p,"North");    add(jScrollPane1,"Center");    sure.addActionListener(new chaxun());    xgai.addActionListener(new chaxun());    tijiao.addActionListener(new chaxun());    model.addColumn("学号");    model.addColumn("姓名");    model.addColumn("成绩");    course.addItem("请选择课程");    tgreade.addItem("请选择班级");    term.addItem("请选择学期");    sql="select cname,Cgreade from T_C,teacher where T_C.tID=teacher.ID and teacher.name='" +tname+ "'";    try{        //给 课程 班级 添加项目      dbconn db=new dbconn();      rs=db.Query(sql);      while(rs.next()) {        course.addItem(rs.getString(1));        tgreade.addItem(rs.getString(2));      }      sql="select distinct Term from T_C,teacher where T_C.tID=teacher.ID and teacher.name='" +tname+ "'";      rs=db.Query(sql);   //给学期添加项目      while(rs.next())        term.addItem(rs.getString(1));    }catch(Exception er) {System.out.println(er.toString());}  }  class chaxun implements ActionListener{    public void actionPerformed(ActionEvent e){      dbconn db=new dbconn();      kc=(String)course.getSelectedItem();      bj=(String)tgreade.getSelectedItem();      xq=(String)term.getSelectedItem();      if(e.getSource()==sure){ //处理 查询 事件        int j=model.getRowCount();        if(j>0){          for(int i=0;i<j;i++)            model.removeRow(0);        }        sql="select SID,Sname,score from S_C where Tgreade='"+bj+"' and Cname='"+kc+"' and Term='"+xq+"'";        try{          rs=db.Query(sql);          int i=0;          while(rs.next()){            i++;            tempvector=new Vector(1,1);            tempvector.add(rs.getString(1));            tempvector.add(rs.getString(2));            //tempvector.add(rs.getFloat(3));            model.addRow(tempvector);          }          if(i==0)            JOptionPane.showMessageDialog(null,"该门课程成绩未录入,请录入成绩!");            dbtable.setEnabled(false);        }catch(Exception e2) {System.out.print(e2.toString());}      }else if(e.getSource()==xgai) {   //处理 修改 事件        dbtable.setEnabled(true);      }else if(e.getSource()==tijiao) {  //处理 提交 事件        int n=model.getRowCount();        PreparedStatement updatestmt;        sql="update S_C set score=? where SID=? and Term='"+xq+"'";        try{          if(model.getValueAt(n-1,2)!=null){            updatestmt=db.conn.prepareStatement(sql);            for(int i=0;i<n;i++){              updatestmt.setString(2,(String) model.getValueAt(i,0));              updatestmt.setFloat(1,Float.parseFloat((String)model.getValueAt(i,2)));              updatestmt.executeUpdate();            }            JOptionPane.showMessageDialog(null,"修改成功!");          }        }catch(Exception e3) {}      }    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -