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

📄 choicefile.java

📁 一个服务器客户模式的小型考试系统,有兴趣的可以DOWN回去后改进成实用的系统(华南农业大学信息学院计算机系).
💻 JAVA
字号:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
public class ChoiceFile extends Panel implements ItemListener,ActionListener,Runnable
{
   Button 得到试题文件=null;
   Choice list=null; 
   Socket  socket=null;
   DataInputStream in=null; 
   DataOutputStream out=null; 
   Thread thread=null;
   boolean success=false, isSelected=false;
   int n=0;
   
   public ChoiceFile()
    {
      得到试题文件=new Button("将试题文件添加到下拉列表中");
      得到试题文件.setEnabled(false);
      得到试题文件.addActionListener(this);
      list=new Choice();
      list.add("**********");
      add(得到试题文件);
      add(list);
      list.addItemListener(this);
      thread=new Thread(this);
    }
  public void setSocketConnection(Socket socket,DataInputStream in,DataOutputStream out)
    {
      this.socket=socket;
      this.in=in;
      this.out=out; 
      try {
            thread.start(); 
          }
      catch(Exception ee)
          {
          }
      if(this.socket!=null)
       {
         得到试题文件.setEnabled(true);
       } 
    }
   public void actionPerformed(ActionEvent e)
    {
         try 
           { 
             out.writeUTF("列出考试文件");
           }
           catch(IOException ee)
           { 
             success=false;
           }
       
    } 
  public void itemStateChanged(ItemEvent e)
    { 
      n=list.getItemCount();
      if(n>=1&&isSelected==true)
        {
          String listItem=list.getSelectedItem();
           try
              {
                out.writeUTF("考试文件的名字:"+listItem);
                out.writeUTF("请通知考试界面考试用时:");
              }
           catch(IOException ee)
              {
              }
        }         
   }
  public String 得到选择的文件名()
   {
    return list.getSelectedItem();
   }
  public void run()
   {
    String s=null;
    list.removeAll();
    while(true)
      { 
        try
           {
             s=in.readUTF();          
              if(s.startsWith("考试文件:"))
                 {
                   String listItem=s.substring(s.indexOf(":")+1);
                   list.add(listItem);
                   isSelected=true;
                 }
               if(s.startsWith("已经全部列出:"))
                 {
                   success=true; 
                   break;
                 }
               
           }
        catch (Exception ee) 
           {
           }   
      }
 }
 public boolean getSuccess()
 { 
   n=list.getItemCount();
   if(n>0&&success==true)
      return true;
   else
      return false;
 }
}

⌨️ 快捷键说明

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