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

📄 stdframe.java

📁 学生成绩管理系统 学生成绩管理系统 学生成绩管理系统 学生成绩管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
   
  }
  if(e.getSource()==jButton7){
   
   Label3.setText("显示平均分");
   Label3.setBackground(Color.GRAY);
   Label3.setVisible(true);
   
  }
  if(e.getSource()==jLabel2){
   jLabel2.setBackground(Color.GRAY);
  }
 }
public void mouseExited(MouseEvent e){

 }
 
 public void datadisplay(String sql){
  try{
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  }
  catch(ClassNotFoundException ce){
      System.out.println("SQLException:"+ce.getMessage());
  }
  try{
      con=DriverManager.getConnection(Sql);
      stmt=con.createStatement();
      rs=stmt.executeQuery(sql);
      int count= Jtb.getRowCount();
      for(int i=0 ;i<count;i++) model.removeRow(0);
      while(rs.next()){
       String n_1=rs.getString(1).trim();
       String n_2=rs.getString(2).trim();
       String n_3=rs.getString(3).trim();
       String n_4=rs.getString(4).trim();
       String n_5=rs.getString(5).trim();
       String n_6=rs.getString(6).trim();
       String n_7=rs.getString(7).trim();
       String row[]={n_1,n_2,n_3,n_4,n_5,n_6,n_7};
       model.addRow(row);
      }
   }
  catch(SQLException e){
   System.out.println("SQLException:"+e.getMessage());
  }
 }  
 
 
 //主函数
 public static void main(String args[]){
    try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  
        }
        catch(ClassNotFoundException e){
               System.out.println(""+e);
        } 
  StdFrame f = new StdFrame();
        f.setVisible(true);
  f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 }
 
 
 class adddialog extends JDialog implements ActionListener{
  
  JLabel jLabel1 = new JLabel("学号");
  JLabel jLabel2 = new JLabel("姓名");
  JLabel jLabel3 = new JLabel("语文");
  JLabel jLabel4 = new JLabel("数学");
  JLabel jLabel5 = new JLabel("英语"); 
  JLabel jLabel6 = new JLabel("物理"); 
  
  JTextField t1=new JTextField(15);
  JTextField t2=new JTextField(15);
  JTextField t3=new JTextField(15);
  JTextField t4=new JTextField(15);
  JTextField t5=new JTextField(15);
  JTextField t6=new JTextField(15);
  
  JButton jButton1=new JButton("添加");
  JButton jButton2=new JButton("取消");
  //jpanel    
  JPanel jpanel=new JPanel();
  JPanel jpanel1=new JPanel();
  public adddialog(){//向面板中添加内容
   jpanel.add(jLabel1);
   jpanel.add(t1);
   jpanel.add(jLabel2);
   jpanel.add(t2);
   jpanel.add(jLabel3);
   jpanel.add(t3);
   jpanel.add(jLabel4);
   jpanel.add(t4);
   jpanel.add(jLabel5);
   jpanel.add(t5);
   jpanel.add(jLabel6);
   jpanel.add(t6);
   jpanel.setLayout(new GridLayout(6,2));
  
   jpanel1.add(jButton1);
   jpanel1.add(jButton2);
   jpanel1.setLayout(new FlowLayout(FlowLayout.CENTER));
  
   add(jpanel);
   add(jpanel1,BorderLayout.SOUTH);
   
   jButton1.addActionListener(this);
   jButton2.addActionListener(this);
  }
  public void actionPerformed(ActionEvent e){//接收传过来的ActionEvent类创建的对象,传递给e,监视器就知道发生的事件
      if( e.getSource() == jButton1 ){
       adddata();
      }
      if( e.getSource() == jButton2 ){
         this.dispose();
       }
  }
   
  public void adddata(){
   try{
       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
   }
   catch(ClassNotFoundException ce){
       System.out.println("SQLException:"+ce.getMessage());
   }
   try{
       con=DriverManager.getConnection(Sql);
       stmt=con.createStatement();
       String  s1=t1.getText();
       String  s2=t2.getText();
       String  s3=t3.getText();
       String  s4=t4.getText();
       String  s5=t5.getText();
       String  s6=t6.getText();
       float  f1= Float.parseFloat(s3);
       float  f2=Float.parseFloat(s4);;
       float  f3=Float.parseFloat(s5);;
       float  f4=Float.parseFloat(s6);;
       float  f5=(f1+f2+f3+f4)/4;
       stmt.executeUpdate("insert into students values('"+s1+"','"+s2+"','"+f1+"','"+f2+"','"+f3+"','"+f4+"','"+f5+"')");
     t1.setText("");
     t2.setText("");
     t3.setText("");
     t4.setText("");
     t5.setText("");
     t6.setText("");
    }
   catch(SQLException e){
    System.out.println("SQLException:"+e.getMessage());
   } 
   JOptionPane.showMessageDialog(null,"添加成功!","添加成功!",JOptionPane.INFORMATION_MESSAGE);    
   datadisplay(sql);
  }
 }

 class displaydialog extends JDialog{
  int fifty=0;
  int sixty=0;
  int seventy=0;
  int eighty=0;
  int ninety=0;
 
  
  float a1,a2,a3,a4,a5;
  public displaydialog(int i){ 
    try{
         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    }
    catch(ClassNotFoundException ce){
         System.out.println("SQLException:"+ce.getMessage());
    }
    try{
         con=DriverManager.getConnection(Sql);
         stmt=con.createStatement();
         rs=stmt.executeQuery(sql);
         while(rs.next()){
          String people=rs.getString(i).trim();
          if(Float.parseFloat(people)<60.0) fifty=fifty+1;
          else if(Float.parseFloat(people)<70.0) sixty=sixty+1;
          else if(Float.parseFloat(people)<80.0) seventy=seventy+1;
          else if(Float.parseFloat(people)<90.0) eighty=eighty+1;
          else if(Float.parseFloat(people)<=100.0) ninety=ninety+1;
         }
       }
       catch(SQLException e){
     System.out.println("SQLException:"+e.getMessage());
    }
  }
  public void paint(Graphics g) {//以饼状图显示
   int all=fifty+sixty+seventy+eighty+ninety;
   
   a1=fifty*100/all;
   a2=sixty*100/all;
   a3=seventy*100/all;
   a4=eighty*100/all;
   a5=ninety*100/all;
   fifty=fifty*360/all;
   sixty=sixty*360/all;
   seventy=seventy*360/all;
   eighty=eighty*360/all;
   ninety=ninety*360/all;
   int position = 360;
         Graphics2D g2D = (Graphics2D) g;//强制类型转换
         g2D.setStroke(new BasicStroke(1.0f));
         
         Insets insets = getInsets();
            int L0 = (insets.left)/2, T0 = (insets.top)/2;
         g.setColor(Color.white); 
            g.fillRect(L0,T0,400,300);
         
          g.setColor(Color.BLACK);
         g.drawString("优秀  (100-90):"+a5+"%", 20, 40);
            g.drawString("良好  ( 89-80):"+a4+"%", 20, 60);
         g.drawString("中等  ( 79-70):"+a3+"%", 20, 80);
            g.drawString("及格  ( 69-60):"+a2+"%", 20, 100);
         g.drawString("不及格( 59- 0):"+a1+"%", 20, 120);
         
         g.setColor(Color.yellow);
         g.fillRect(150, 30, 60, 10);
         g.fillArc(150, 130, 150, 150, position, -ninety);
         position -= ninety;
         
         g.setColor(Color.GREEN);
         g.fillRect(150, 50, 60, 10);
         g.fillArc(150, 130, 150, 150, position, -eighty);
         position -= eighty;
         
         g.setColor(Color.pink);
         g.fillRect(150, 70, 60, 10);
         g.fillArc(150, 130, 150, 150, position, -seventy);
         position -= seventy;
         
         g.setColor(Color.CYAN);
         g.fillRect(150, 90, 60, 10);
         g.fillArc(150, 130, 150, 150, position, -sixty);
         position -= sixty;
         
         g.setColor(Color.red);
         g.fillRect(150, 110, 60, 10);
         g.fillArc(150, 130, 150, 150, position, -fifty);
         position -= fifty;
         
  }
 }
 class averagedialog extends JDialog{
   JScrollPane js=new JScrollPane();
   JTable jtable2=new JTable();
   Vector tableData2=new Vector();
   Vector rowData2=new Vector();
   averagedialog(){
    tableData2.addElement("学号");
       tableData2.addElement("姓名");
    tableData2.addElement("平均分"); 
    DefaultTableModel model2=(DefaultTableModel) jtable2.getModel();
       model2.setDataVector(rowData2, tableData2);
        
       try{
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    }
    catch(ClassNotFoundException ce){
         System.out.println("SQLException:"+ce.getMessage());
    }
    try{
        con=DriverManager.getConnection(Sql);
         stmt=con.createStatement();
         rs=stmt.executeQuery(sql);
        int count= jtable2.getRowCount();
        for(int i=0 ;i<count;i++) model2.removeRow(0);
         while(rs.next()){
         String n_1=rs.getString(1).trim();
         String n_2=rs.getString(2).trim();
         String n_7=rs.getString(7).trim();
          String row[]={n_1,n_2,n_7};
         model2.addRow(row);
         }
     }
    catch(SQLException e){
     System.out.println("SQLException:"+e.getMessage());
    } 
        
    js.getViewport().add(jtable2,null);
    add(js);
   }   
 }
 
}

 

//存为Kechengbiao1.java


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


public class Kechengbiao1 extends JDialog implements ActionListener{//负责显示记录的类
    JTable table;
    Object a[][];
    Object name[]={"节数","星期一","星期二","星期三","星期四","星期五","星期六","星期日"};
    JButton kechengbiao1; 
    JButton exit; 
    Connection con;
    Statement sql; 
    ResultSet rs;
    Kechengbiao1(String title)
    {  setTitle(title);
       kechengbiao1=new JButton("单击显示第一学期课程表");
       exit=new JButton("退出");
       kechengbiao1.addActionListener(this);
       exit.addActionListener(this);
       add(kechengbiao1,BorderLayout.NORTH);
       JPanel pSouth=new JPanel();
       pSouth.add(exit);
       add(pSouth,BorderLayout.SOUTH);
       setBounds(300,40,600,250);
    }
    public void actionPerformed(ActionEvent e){
     if(e.getSource()==exit){
   System.exit(0);
  }
       try{ con=DriverManager.getConnection("jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=students.mdb");
            sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
            rs=sql.executeQuery("SELECT * FROM kebiao");
            rs.last();
            int lastNumber=rs.getRow();
            a=new Object[lastNumber][8];
            int k=0;
            rs.beforeFirst();
            while(rs.next()){
                 a[k][0]=rs.getString(1);
                 a[k][1]=rs.getString(2);  
                 a[k][2]=rs.getString(3);
                 a[k][3]=rs.getString(4);
                 a[k][4]=rs.getString(5);
                 a[k][5]=rs.getString(6);
                 a[k][6]=rs.getString(7);
                 a[k][7]=rs.getString(8);
                 k++;
           }
           con.close();
       }  
       catch(SQLException ee){ 
           System.out.println(ee);
       } 
       table=new JTable(a,name);
       getContentPane().removeAll();
       add(kechengbiao1,BorderLayout.NORTH);
       add(new JScrollPane(table),BorderLayout.CENTER);
       validate();
    }      
}

⌨️ 快捷键说明

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