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

📄 da123.java

📁 简单的奖学金评定系统
💻 JAVA
字号:
import java.sql.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Da123 extends JFrame implements ActionListener
{
   JButton button_add,button_ok,button_judge,button_delete;
   JPanel panel;
   JTabbedPane pane;
   JTable table;
   String title[]={"学号","姓名","语文","数学","英语","专业课","总分","奖学金级别"};
   Object body[][]=new Object[50][8];
   JFrame f;
   Container c;
   String strurl;
   Connection conn;
   Statement stmt;
   ResultSet rs;
   JDialog dialog,dialog1,dialog2,dialog3;
   JTextField t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13;
   JButton but1,but2,but3;
   JLabel label,label1;
   JTextField text1;
   JButton button1,button2,button3;
    public Da123() 
    {
        f = new JFrame();
	    c = f.getContentPane( );
	    f.setTitle("学生评定系统");
        f.setSize(550,300);
        f.setLocation(300,200);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        
        c.setLayout(new BorderLayout());
        panel = new JPanel();
        
        button_add = new JButton("添加");
        panel.add(button_add);
        button_add.addActionListener(this);
        button_delete = new JButton("删除");
        panel.add(button_delete);
        button_delete.addActionListener(this);
        button_ok = new JButton("显示");
        panel.add(button_ok);
        button_ok.addActionListener(this);
        button_judge = new JButton("评定");
        panel.add(button_judge);
        button_judge.addActionListener(this);
        
        c.add(panel,"South");
        pane = new JTabbedPane();
        table = new JTable(body,title);
        pane.add("学生成绩表",new JScrollPane(table));
        c.add(pane,"Center");
        f.setVisible(true);
            
        dialog = new JDialog(this,"提示",true);
		dialog.setLocation(450, 350);
        label = new JLabel("");
	    dialog.add(label);
	    dialog.setSize(300,100);
	    
	    dialog1 = new JDialog(this,"填加信息",true);
	    
	    dialog1.setLocation(350, 350);
	    dialog1.setSize(200,250);
	    
	    dialog1.setLayout(new FlowLayout());
        t1=new JTextField("输入学号:");
        t1.setEditable(false);
        t2=new JTextField(10);
        t3=new JTextField("输入姓名:");
        t3.setEditable(false);
        t4=new JTextField(10);
        t5=new JTextField("输入语文:");
        t5.setEditable(false);
        t6=new JTextField(10);
        t7=new JTextField("输入数学:");
        t7.setEditable(false);
        t8=new JTextField(10);
        t9=new JTextField("输入英语:");
        t9.setEditable(false);
        t10=new JTextField(10);
        t11=new JTextField("输入专业课:");
        t11.setEditable(false);
        t12=new JTextField(10);
        but1=new JButton("Y");
        but2=new JButton("Exit");
        but3=new JButton("N");
        dialog1.add(t1);
        dialog1.add(t2);
        dialog1.add(t3);
        dialog1.add(t4);
        dialog1.add(t5);
        dialog1.add(t6);
        dialog1.add(t7);
        dialog1.add(t8);
        dialog1.add(t9);
        dialog1.add(t10);
        dialog1.add(t11);
        dialog1.add(t12);
        dialog1.add(but1);
        dialog1.add(but2);
        dialog1.add(but3);
        but1.addActionListener(this);
        but2.addActionListener(this);
        but3.addActionListener(this);
        
        dialog2 = new JDialog(this,"提示",true);
		dialog2.setLocation(450, 350);
        label1 = new JLabel("");
	    dialog2.add(label1);
	    dialog2.setSize(300,100);
	    
	    dialog3 = new JDialog(this,"删除的学号",true);
		dialog3.setLocation(450, 350);
		dialog3.setLayout(new FlowLayout());
        text1 = new JTextField(13);
	    dialog3.add(text1);
	    button1 = new JButton("Y");
	    dialog3.add(button1);
	    button1.addActionListener(this);
	    button2 = new JButton("Exit");
	    dialog3.add(button2);
	    button2.addActionListener(this);
	    button3 = new JButton("N");
	    dialog3.add(button3);
	    button3.addActionListener(this);
	    dialog3.setSize(200,100);
	    button1.addActionListener(this);
        button2.addActionListener(this);
        button3.addActionListener(this);
     }
		
	public void actionPerformed(ActionEvent e)
			{
					if(e.getSource()==button_ok)
				{
					ok();
				}
				if(e.getSource()==button_judge)
				{
					judge();
				}
			
				if(e.getSource()==button_add)
				{
					dialog1.setVisible(true);
				}
				if(e.getSource()==button_delete)
				{
					dialog3.setVisible(true);
				}
				if(e.getSource()==button1)
				{
				   delete();
				   dialog3.setVisible(false);
				   text1.setText("");
				 }
	
				if(e.getSource()==but1)
				{
					add();
				}
				if(e.getSource()==but2)
				{
				 dialog1.setVisible(false);
				 t2.setText("");
				 t4.setText("");
				 t6.setText("");
				 t8.setText("");
				 t10.setText("");
				 t12.setText("");
				 }
				if(e.getSource()==but3)
				{
				 t2.setText("");
				 t4.setText("");
				 t6.setText("");
				 t8.setText("");
				 t10.setText("");
				 t12.setText("");
				 }
			}

    public void ok()
				{
					    try
					    {
					    	connect();
					       	int m=0;
				            while(rs.next())
				            {
				            	
					            body[m][0]=rs.getString("sno");
					            body[m][1]=rs.getString("sname");
					            body[m][2]=rs.getString("course1");
					            body[m][3]=rs.getString("course2");
					            body[m][4]=rs.getString("course3");
					            body[m][5]=rs.getString("course4");
					            body[m][6]=rs.getString("sum");
					            m++;
					            f.repaint();
					          }
					          rs.close();
						      stmt.close();
						      conn.close();
					    }        
					    catch(Exception sad)
					    {
					    	label.setText("连接数据库出错!");
						    dialog.setVisible(true);
					    }
				}

	public void delete() 
				{
					try
					{
						connect();
					
						stmt.executeUpdate("Delete from student where sno='"+text1.getText()+"'");
					
					    int m=50;
						for(int i=0;i<=m;i++)
						{
							int x = Integer.parseInt(text1.getText());
							int y = Integer.parseInt(body[i][0].toString());
							if(x==y)
							{
								body[i][0]="";
								body[i][1]="";
								body[i][2]="";
								body[i][3]="";
								body[i][4]="";
								body[i][5]="";
								body[i][6]="";
								body[i][7]="";
								for(;i<=m;i++)
								{
									body[i][0]=body[i+1][0];
								    body[i][1]=body[i+1][1];
									body[i][2]=body[i+1][2];
									body[i][3]=body[i+1][3];
									body[i][4]=body[i+1][4];
									body[i][5]=body[i+1][5];
									body[i][6]=body[i+1][6];
									body[i][7]=body[i+1][7];
								}
								this.repaint();
	
							}
					     }
					}	
					catch (Exception s)
					{
					System.out.println("按  显示  查看结果!");
					}
		    	}
				
	public void judge()
	{
		
	   try
					    {
					    	connect();
					       	int m=0;
				            while(rs.next())
				            {
				            	
					            body[m][0]=rs.getString("sno");
					            body[m][1]=rs.getString("sname");
					            body[m][2]=rs.getString("course1");
					            body[m][3]=rs.getString("course2");
					            body[m][4]=rs.getString("course3");
					            body[m][5]=rs.getString("course4");
					            body[m][6]=rs.getString("sum");
					            body[m][7]=rs.getString("scholarship");
					            m++;
					            f.repaint();
					          }
					          rs.close();
						      stmt.close();
						      conn.close();
					    }        
					    catch(Exception sad)
					    {
					    	label.setText("连接数据库出错!");
						    dialog.setVisible(true);
					    }
      }	  		         					            
					           
	public void add()
				{   int sum=0;
			    	String scholarship;
				    String a1=new String(t2.getText());
				    String a2=t4.getText();
					int a3=Integer.parseInt(t6.getText());
					int a4=Integer.parseInt(t8.getText());
					int a5=Integer.parseInt(t10.getText());
					int a6=Integer.parseInt(t12.getText());
				    sum=a3+a4+a5+a6;
       
         if(sum>=360)
         {
       	  scholarship=new String("一");
         }
         else if(sum>=340)
         {
       	 scholarship=new String("二");
         }
         else if(sum>=320)
         {
       	  scholarship=new String("三");
         }
         else
         {
       	 scholarship=new String("无");
         }
         try{
							 connect();
							 
							 stmt.executeUpdate("insert into student (sno,sname,course1,course2,course3,course4,sum,scholarship) values ('"+a1+"','"+a2+"','"+a3+"','"+a4+"','"+a5+"','"+a6+"','"+sum+"','"+scholarship+"')");

							 dialog1.setVisible(false);
							 t2.setText("");
							 t4.setText("");
							 t6.setText("");
							 t8.setText("");
							 t10.setText("");
							 t12.setText("");	
						}
					catch(Exception ee)
						{
							 label1.setText("插入有错!");
						     dialog2.setVisible(true);
						}
				}

    public void connect()
				{
					try
					{
						strurl="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=D:\\database.mdb";
					    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
						conn=DriverManager.getConnection(strurl) ;
						stmt=conn.createStatement();
					    rs=stmt.executeQuery("select * from student");     
					}
					catch (Exception s)
				         {
				         	label.setText("连接数据库出错!");
						    dialog.setVisible(true);
				         }
					 
				}	
				   
	public static void main(String args[])
		{
			new Da123();
			
		}
} 

⌨️ 快捷键说明

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