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

📄 rankadd.java

📁 学籍管理系统,可以实现多方面学生学籍的管理
💻 JAVA
字号:
/*
 * Created on 2005-12-6
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

/**
 * @author tian
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
import java.net.*;
import java.io.*;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;

public class rankAdd extends Applet implements Runnable,ActionListener,ItemListener
{
	  TextField txt_sno;  
	  TextField txt_sname; 
	  TextField txt_subno;  
	  TextField txt_score;
	  
	  Label lab_sno;
	  Label lab_sname;
	  Label lab_subno;
	  Label lab_subname;
	  Label lab_score;
	  
	  Choice choice=null; 
	  
	  Button btn_add=new Button();
	  Label tishi;
	  Label xianshi;
	  
	  Socket socket=null;
	  DataInputStream in=null;
	  DataOutputStream out=null;
	  Thread thread; 
	  
	   Connection con=null;
	   Statement  stmt=null;
	   ResultSet  rs;

	public void init(){
		  choice=new Choice();
		  txt_sno=new TextField(10);		 
		  txt_sname=new TextField(10);	
		  txt_subno=new TextField(10);		 
		  txt_subno.setEditable(false);
		  txt_score=new TextField(10);	
		  lab_sno=new Label("学号",Label.CENTER);
		  lab_sname=new Label("姓名",Label.CENTER);
		  lab_subno=new Label("科目编号",Label.CENTER);
		  lab_subname=new Label("科目",Label.CENTER);
		  lab_score=new Label("考试成绩",Label.CENTER);
		  
		  btn_add=new Button("添加");//又添加	  
		  tishi=new Label("正在连接到服务器,请稍等...",Label.CENTER);
		  tishi.setForeground(Color.red);
		  tishi.setFont(new Font("TimesRoman",Font.BOLD,24));
		  xianshi=new Label("提示结果");
		  //..............................
		
	
		  //..............................
		  
		  Panel box1=new Panel();  
		  Panel box2=new Panel();  
		  Panel box3=new Panel();
		  Panel box4=new Panel();
		  Panel box5=new Panel();
		  Panel box6=new Panel();
		  Panel box7=new Panel();
		  Panel box8=new Panel();
		  
		  box1.add(new Label("输入添加内容:",Label.CENTER));
		  box2.add(xianshi);
		  
		  box3.add(lab_sno);
		  box3.add(txt_sno);
		  box4.add(lab_sname);
		  box4.add(txt_sname);
		  box5.add(lab_subno);
		  box5.add(txt_subno);
		  box6.add(lab_subname);
		  box6.add(choice);
		  box7.add(lab_score);
		  box7.add(txt_score);
		 // box8.add(choice);
		 		  
		  box1.add(btn_add);//又添加	
	
		  add(tishi);
		  add(box1);
		  add(box3); 
		  add(box4);
		  add(box6);
		  add(box5);		
		  add(box7);
		  add(box2);
          add(box8);
       
		  btn_add.addActionListener(this);//又添加	
		  choice.addItemListener(this);
		  //------------------------------------------
		  try {
		    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		   }
		catch(ClassNotFoundException e)
		        {System.out.println("ClassNotFoundException"+e.getMessage());}
		try{
		   con=DriverManager.getConnection("jdbc:odbc:graduate","liuwei","123456");
		   stmt=con.createStatement();
		  }
		catch(SQLException ee)
		{System.out.println("jdbc:odbc:"+ee.getMessage());}
		  //------------------------------------------
		}
	public void start(){
		if(socket!=null&&in!=null&&out!=null)
      {  try
            {
              socket.close();
              in.close(); 
              out.close();
            }
        catch(Exception ee)
            {
            }
      }
   try
      {
        socket=new Socket(this.getCodeBase().getHost(), 6665);
        in=new DataInputStream(socket.getInputStream());
        out=new DataOutputStream(socket.getOutputStream());
      }
   catch (IOException ee)
      { 
       tishi.setText("连接失败");
      }
   if(socket!=null)
      {
        InetAddress address=socket.getInetAddress();
        tishi.setText("连接:"+address+"成功");
      } 
   if(thread==null)
      {
        thread=new Thread(this);
        thread.start();
      }
   //choice.add("sdfsfds");在该处可以
   //...............................
 /* try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
   }
catch(ClassNotFoundException e)
        {System.out.println("ClassNotFoundException"+e.getMessage());}
try{
   con=DriverManager.getConnection("jdbc:odbc:graduate","liuwei","123456");
   stmt=con.createStatement();
  }
catch(SQLException ee)
{System.out.println("jdbc:odbc:"+ee.getMessage());}*/
   //...............................
String sqlCondition="SELECT * FROM subject";
	try{           
  rs=stmt.executeQuery(sqlCondition);
 while(rs.next())
   {
  	String user=rs.getString(2);
  	choice.add(user);                  
   }
 }
catch(SQLException ee) {
System.out.println("异常"+ee.getMessage());	
}
//。。。。。。。。。。。。。。。。。。。。
		}
	
	public void run(){
		String s=null;
	    while(true)
	     { 
	       try{
	             s=in.readUTF();
	            
	          }
	        catch (IOException e)
	          {
	            tishi.setText("与服务器已断开");
	            break;
	          }
	     xianshi.setText("添加成功");
	    }

		}
	//..........
	public void actionPerformed(ActionEvent e)
	 {
	   if(e.getSource()==btn_add)
	     { 
	       String s1="",s2="",s3="",s4="",s5="";
	       String tianjia=btn_add.getLabel();//有写的
	      
	       s1=txt_sno.getText();
	       s2=txt_sname.getText();
	       s3=txt_subno.getText();
	       s4=choice.getSelectedItem(); 
	       s5=txt_score.getText();
	      
	       String str=s1+","+s2+","+s3+","+s4+","+s5;      
	       if(str.length()>0)		      
	        { 
	          try{
	              out.writeUTF(str);
	             }
	          catch(IOException e1)
	             {
	              tishi.setText("与服务器已断开");
	             } 
	        } 
	       else
	        {
	       	xianshi.setText("请填写");
	        }              
	       
	     }
	   
	   //.................
	   if (e.getModifiers()==choice.getSelectedIndex())
	   {
	   String ss=choice.getSelectedItem(); 
	   String sql="SELECT sub_name FROM subject where sub_no='"+ss+"'";
	   try{
	   	rs=stmt.executeQuery(sql);
	   	String user=rs.getString(1);
	   	txt_sname.setText(user);
	   }
	  catch(SQLException ee)
	  {}
	   }
	 }
	public void itemStateChanged(ItemEvent e)
	  {
		 String str=choice.getSelectedItem();
	   // String sql="select sub_name From subject where sub_no='"+str+"'";
		// txt_subname.setText("测试");
		 if (e.getItemSelectable() instanceof Choice)
		 {  //txt_subname.setText("测试");
		   String ss=choice.getSelectedItem(); 
		   String sql="SELECT sub_no FROM subject where sub_name='"+str+"'";
		   try{
		   	rs=stmt.executeQuery(sql);
		   	while(rs.next())
		   	{
		   	String user=rs.getString(1);
		   	txt_subno.setText(user);
		   	}
		   }
		  catch(SQLException ee)
		  { System.out.println("yichang"+ee.getMessage());}
		 
		 	}
	 //txt_subname.setText("测试");
		 	
	  }


	
}



⌨️ 快捷键说明

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