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

📄 examinationclient.java

📁 用java做的试题库,好精简的. 请大家参考一下的哦.多指教的.
💻 JAVA
字号:
import java.net.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;

class 考号文本框 extends TextField implements KeyListener
{
 考号文本框(int n)
  {
  super(n);
  this.addKeyListener(this);
  }
  public void keyPressed(KeyEvent e)
  {
  int c=e.getKeyCode();
  boolean b1=(c<'0'||c>'9'),b2=(c!='.'),b3=(c!=KeyEvent.VK_BACK_SPACE);
  if(b1&&b2&&b3)
  {
  String temp=this.getText().substring(0,this.getText().indexOf(c));
  this.setText(temp);
  }
  }
public void keyTyped(KeyEvent e)
{
}
public void keyReleased(KeyEvent e)
{
}
}

class 答题卡 extends Panel implements ItemListener
{
  Checkbox box_a,box_b,box_c,box_d;
  Label label;
  int number;
  CheckboxGroup group;
  String answer="?";
  答题卡()
  {
      number = 0;
      group = new CheckboxGroup();
      box_a = new Checkbox("A", false, group);
      box_b = new Checkbox("B", false, group);
      box_c = new Checkbox("C", false, group);
      box_d = new Checkbox("D", false, group);
      box_a.addItemListener(this);
      box_b.addItemListener(this);
      box_c.addItemListener(this);
      box_d.addItemListener(this);
      label = new Label("(" + number + "(");
      add(label);
      add(box_a);
      add(box_c);
      add(box_d);
    }
  public void itemStateChanged(ItemEvent e)
  {
   Checkbox box=(Checkbox)e.getItemSelectable();
   answer=box.getLabel();
   box.setFont(new Font("Courier",Font.BOLD,18));
   box.setForeground(Color.red);
   if(box_a!=box)
   {
    box_a.setFont(new Font("TimesRoman",Font.PLAIN,12));
    box_a.setForeground(Color.black);
    }
    if(box_b!=box)
    {
    box_b.setFont(new Font("TimesRoman",Font.PLAIN,12));
    box_b.setForeground(Color.black);
    }
    if(box_c!=box)
    {
      box_c.setFont(new Font("TimesRoman",Font.PLAIN,12));
      box_c.setForeground(Color.black);
    }
    if(box_d!=box)
    {
       box_d.setFont(new Font("TimesRoman",Font.PLAIN,12));
       box_d.setForeground(Color.black);
    }
    }
}
public class ExaminationClient extends Applet implements Runnable,ActionListener
    {
        TextField 姓名 = new TextField(10);
        考号文本框 考号 = new 考号文本框(18);
        TextArea 试题区 = new TextArea();
        Socket socket = null;
        DataInputStream in = null;
        DataOutputStream out = null;
        Button 开始考试 = new Button("开始考试");
        Button 提交试卷 = new Button("提交试卷");
        Thread thread = null;
        答题卡 题卡[] = new 答题卡[21];
        Choice choice = null;
        int N = 0;

        public void init() {
            setLayout(null);
            choice = new Choice();
            N = Integer.parseInt(getParameter("总数"));
            for (int i = 1; i <= N; i++) {
                choice.add(getParameter(String.valueOf(i)));
            }
            Panel p = new Panel();
            p.setLayout(new GridLayout(22, 1));
            p.add(new Label("(一)选择填空题(共10小题)"));
            for (int i = 1; i <= 10; i++) {
                题卡[i] = new 答题卡();
                题卡[i].label.setText("(" + i + ")");
                p.add(题卡[i]);
            }
            p.add(new Label("(二)阅读理解:"));
            for (int i = 11; i <= 15; i++) {
                题卡[i] = new 答题卡();
                int m = i - 10;
                题卡[i].label.setText("(" + m + ")");
                p.add(题卡[i]);
            }
            ScrollPane scroll = new ScrollPane();
            scroll.add(p);
            add(试题区);
            int height, width;
            height = getSize().height;
            width = getSize().width;
            scroll.setBounds(0, 32, 2 * width / 5, height - 65);
            试题区.setBounds(2 * width / 5 + 2, 32, 3 * width / 5 - 10, height - 65);
            试题区.setEditable(false);
            Panel north = new Panel();
            Label L1 = new Label("输入姓名:", Label.CENTER);
            Label L2 = new Label("输入考号:", Label.CENTER);
            north.add(L1);
            north.add(姓名);
            north.add(L2);
            north.add(考号);
            north.add(new Label("选择一套试题:"));
            north.add(choice);
            add(north);
            north.setBounds(20, 2, width - 25, 30);
            Panel south = new Panel();
            south.add(提交试卷);
            add(south);
            south.setBounds(2 * width / 5 + 2, height - 35, 3 * width / 5 - 4, 30);
            开始考试.addActionListener(this);
            提交试卷.addActionListener(this);
        }

        public void start() {
            if (thread == null) {
                thread = new Thread(this);
                thread.setPriority(Thread.MIN_PRIORITY);
                thread.start();
            }
        }

        public void run() {
            String s = null;
            try {
                socket = new Socket(this.getCodeBase().getHost(), 6331);
                in = new DataInputStream(socket.getInputStream());
                out = new DataOutputStream(socket.getOutputStream());
            } catch (IOException e) {} while (true) {
                try {
                    s = in.readUTF();
                    if (s != null) {
                        试题区.append(s + "\n");
                    }
                } catch (IOException e) {
                    姓名.setText("已经和服务器断开");
                    break;
                }
            }
        }

        public void actionPerformed(ActionEvent e) {
            if (e.getSource() == 开始考试) {
                String name1 = "必须输入姓名";
                String kaohao1 = "必须输入考号";
                kaohao1 = 考号.getText() + kaohao1;
                if (name1.startsWith("必须输入姓名") && kaohao1.startsWith("必须输入考号")) {
                    姓名.setText("必须输入姓名");
                    考号.setText("必须输入考号");
                } else if (name1.startsWith("必须输入姓名")) {
                    姓名.setText("必须输入姓名");
                } else if (kaohao1.startsWith("必须输入考号")) {
                    考号.setText("必须输入考号");
                } else {
                    try {
                        out.writeUTF("start;" + choice.getSelectedItem());
                    } catch (IOException e1) {}
                }
            }
            if (e.getSource() == 提交试卷) {
                StringBuffer s = new StringBuffer();
                for (int i = 1; i <= 15; i++) {
                    s.append(题卡[i].answer);
                }
                try {
                    out.writeUTF(new String(s) + "#" + 姓名.getText() + 考号.getText() +
                                 "###");
                } catch (IOException e1) {}
                开始考试.setEnabled(false);
                提交试卷.setEnabled(false);
            }
        }
    }




⌨️ 快捷键说明

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