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

📄 testsystem.java

📁 考试系统
💻 JAVA
字号:

/* 考试系统的主类  显示主界面
 */

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JOptionPane;
 import javax.swing.border.*;

public class TestSystem extends JFrame implements ActionListener
 {  JLabel wlcomeLabel;
 	  JTextField nameText,numberText,classText;
 	  String strName=null,strNumber=null,strClass=null;
 	  JButton startButton;
 	  Box boxV1,boxV2,baseBox;
 	  JPanel pan1=null,pan2=null,pan30,pan31,pan32,pan4;
 	  TestArea testPanel=null;//考试界面
    public TestSystem()
     {  super("标准化模拟考试系统");
     	  setLayout(new BorderLayout());
     	  wlcomeLabel=new JLabel("欢迎光临英语考试系统",JLabel.CENTER);
     	  wlcomeLabel.setFont(new Font("隶书",Font.PLAIN,24));//设置字体及大小
     	  wlcomeLabel.setForeground(Color.red);
     	  startButton=new JButton("进入");
     	  startButton.setForeground(Color.red);
     	  startButton.addActionListener(this);
     	  pan1=new JPanel();// 面板pan
     	  pan1.add(startButton);
     	  nameText=new JTextField(8);
     	  numberText=new JTextField(8);
     	  classText=new JTextField(8);

        boxV1=Box.createVerticalBox(); //列式
        boxV1.add(Box.createVerticalStrut(10));
        boxV1.add(new JLabel("姓名:"));
        boxV1.add(Box.createVerticalStrut(10));
        boxV1.add(new JLabel("学号:"));
        boxV1.add(Box.createVerticalStrut(10));
        boxV1.add(new JLabel("班级:"));
        boxV2=Box.createVerticalBox(); //列式
        pan30=new JPanel();
        pan30.add(nameText);
        boxV2.add(pan30);
        boxV1.add(Box.createVerticalStrut(1));
        pan31=new JPanel();
        pan31.add(numberText);
        boxV2.add(pan31);
        boxV1.add(Box.createVerticalStrut(1));
        pan32=new JPanel();
        pan32.add(classText);
        boxV2.add(pan32);
        baseBox=Box.createHorizontalBox();//行
        baseBox.add(boxV1);
        baseBox.add(Box.createHorizontalStrut(10));
        baseBox.add(boxV2);
        pan2=new JPanel();
        pan2.add(baseBox);

        add(wlcomeLabel,BorderLayout.NORTH);
        pan4=new JPanel();
        pan4.setLayout(new BorderLayout());
        pan4.add(pan2,BorderLayout.NORTH);
        pan4.add(pan1,BorderLayout.CENTER);
        add(pan4,BorderLayout.CENTER);
        testPanel=new TestArea();
        //add(testPanel,BorderLayout.SOUTH);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//窗口的退出
        setBounds(100,100,400,400);
        //setBackground(Color.red);
        setVisible(true);
        validate();
     }//public TestSystem()


    public void actionPerformed(ActionEvent e)
     {  strName=nameText.getText().trim();


     	  strNumber=numberText.getText().trim();
     	  strClass=classText.getText().trim();
     	  if(strName.length()>0)
     	   {  if(strNumber.length()>0)
     	   	   {   if(strClass.length()>0)
     	   	   	    {  remove(pan4);
     	   	   	    	 wlcomeLabel.setText("hello "+strName+"同学!");
     	   	   	    	 add(testPanel,BorderLayout.CENTER);
                     setBounds(100,100,600,600);
     	   	   	    	 setVisible(true);
     	   	   	    	 validate();
     	   	   	    }
     	   	   	   else
     	   	   	    {  JOptionPane.showMessageDialog(this,"请输入你的班级",
 	   	   	                                "",JOptionPane.WARNING_MESSAGE);
     	   	   	    }
     	   	   }
     	   	  else
     	   	   {  JOptionPane.showMessageDialog(this,"请输入你的学号",
 	   	   	                                "",JOptionPane.WARNING_MESSAGE);
     	   	   }
     	   }
     	  else
     	   {  JOptionPane.showMessageDialog(this,"请输入你的姓名",
 	   	   	                                "",JOptionPane.WARNING_MESSAGE);
     	   }
     }// public void actionPerformed(ActionEvent e)

     public String getName()
     {
     	  return strName;
     }
    public String getNumber()
     {  //strNumber=numberText.getText().trim();
     	  return strNumber;
     }
    public String gettClass()
     {  //strClass=classText.getText().trim();
     	  return strClass;
     }


    public static void main(String[] args)
     {  TestSystem tt=new TestSystem();
     	  //String t1=tt.getName();
     	  //.out.println("name="+t1);
     }//main
 }//public class TestSystem

⌨️ 快捷键说明

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