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

📄 onlinetest.java

📁 简单的在线考试系统 提供添加修改 考试等操作
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
import olts.*;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.event.*;

/**An Online Testing System (OLTS) using Microsoft Access database
 * that allows user to inserted,updated and deleted test questions,
 * and users also can take a exam base on these question available 
 * in the database,it provide you a single question exam and also a compound
 * examination.and it will present you the marks you hava got.
 * @author weijun wei
 * @version 1.0
 */
public class OnlineTest extends JFrame{
	/**this class is the main class and also the presented class which 
	 * provide users a GUI interface to take certain command base on this system; 
	 * @param args
	 */
	private static final long serialVersionUID = 0L;	
	//reference for manipulating user interface.
	private static JDesktopPane desktop;
	private TestCommand questionDatabase;
	public static String questionType;
	static int num=1;
	
	//reference to Action
	Action singleInsertAction;
	Action trueflaseInsertAction;
	Action blankInsertAction;
	Action truefalseSaveAction;
	Action blankSaveAction;
	Action saveAction;
	Action deleteAction; 
	Action searchAndUpdataAction;
	Action compoundTestAction;
	Action singleTestAction;
	Action markAction;
	Action helpAction;
	
	public OnlineTest()
	{
		super("Online Testing System (OLTS)");
		//create database connection ~~
		try{
			questionDatabase=new DatabaseSQLCommand();
		}
		catch(Exception e){
			e.printStackTrace();
			System.exit(1);
		}
		
		JToolBar toolBar=new JToolBar();
		JMenu fileMenu=new JMenu("试题维护");
		JMenu subInsertMenu=new JMenu("新建试题");
		JMenu testMenu=new JMenu("在线考试");
		JMenu singleTestMenu=new JMenu("考试类型");
		JMenu helpMenu=new JMenu("帮助");
		testMenu.setMnemonic('t');
		fileMenu.setMnemonic('F');
		helpMenu.setMnemonic('H');
		
		//set up actions for respective command,
		//private inner classes encapsulate the processing of each command.
		singleInsertAction=new SingleInsertAction();
		saveAction=new SaveAction();
		saveAction.setEnabled(false);
		trueflaseInsertAction=new TruefalseInsertAction();
		blankInsertAction=new BlankInsertAction();
		//saveAction.setEnabled(false);
		deleteAction=new DeleteAction();
		//deleteAction.setEnabled(false);
		searchAndUpdataAction=new SearchAndUpdataAction();
		compoundTestAction=new CompoundTestAction();
		singleTestAction=new SingleTestAction();
		markAction=new MarkAction();
		markAction.setEnabled(false);
		helpAction=new HelpAction();
		
		//add filemenu to File menu
		fileMenu.add(subInsertMenu);
		fileMenu.add(saveAction);
		fileMenu.add(deleteAction);
		fileMenu.add(searchAndUpdataAction);
		//fileMenu.addSeparator();
		//fileMenu.add(testAction);
		fileMenu.add(helpAction);
		helpMenu.add(helpAction);
		
		//add actions to testmenu
		testMenu.add(singleTestMenu);
		testMenu.add(markAction);
		testMenu.add(helpAction);
		
		//add menu to subInsertMenu
		subInsertMenu.add(singleInsertAction);
		subInsertMenu.add(trueflaseInsertAction);
		subInsertMenu.add(blankInsertAction);
		
		//add menu to singleTestMenu
		singleTestMenu.add(singleTestAction);
		singleTestMenu.add(compoundTestAction);		
		
		//add actions to tool bar.
		toolBar.add(singleInsertAction);
		toolBar.add(trueflaseInsertAction);
		toolBar.add(blankInsertAction);	
		toolBar.addSeparator();
		toolBar.add(saveAction);
		toolBar.addSeparator();
		toolBar.add(searchAndUpdataAction);
		toolBar.add(deleteAction);
		toolBar.addSeparator();
		toolBar.add(singleTestAction);
		toolBar.add(compoundTestAction);
		toolBar.addSeparator();
		toolBar.add(markAction);
		toolBar.addSeparator();
		toolBar.add(helpAction);
		
		//set up menu bar
		JMenuBar menuBar=new JMenuBar();
		menuBar.add(fileMenu);
		menuBar.add(testMenu);
		menuBar.add(helpMenu);
		setJMenuBar(menuBar);
		
		//set up desktop
		desktop=new JDesktopPane();
		
		//get the content pane to get set up GUI
		Container container=getContentPane();
		container.add(toolBar, BorderLayout.NORTH);
		container.add(desktop, BorderLayout.CENTER);
		
		//register for windowClosing event in case user
		//does not select exit from file menu to terminate application
		addWindowListener(
				//inner method
				new WindowAdapter(){
					public void windowClosing(WindowEvent event){
						shutDown();
					}			
		});
		
		//set window size and display window
		Toolkit toolkit=getToolkit();
		Dimension dimension=toolkit.getScreenSize();
		
		//center window on screen
		setBounds(100,100,dimension.width-100,dimension.height-200);
		setVisible(true);
	}
	private void shutDown(){
		//database.close();
		System.exit(0);
	}
	private SingleTestQuestionEntryFrame creatSingleTestQuestionEntryFrame(){
		//inner class to create new frame 
		SingleTestQuestionEntryFrame frame=new SingleTestQuestionEntryFrame();
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		frame.addInternalFrameListener(new InternalFrameAdapter(){
			public void internalFrameActivated(InternalFrameEvent event){
				saveAction.setEnabled(true);
			}
			public void internalFrameDeactivated(InternalFrameEvent event){
				saveAction.setEnabled(false);
			}
		});
		return frame;		
	}
	private class SingleInsertAction extends AbstractAction{
		/**
		 * 	private inner class defines action that enables users
	     *  to input new test question.if user want to save the question information
	     *  then you must invoke the savaAction command.
		 */
		private static final long serialVersionUID = 1L;
		//set up action's id,difficulty,timelimited,content,answer and score.
		public SingleInsertAction(){
			//inner method for implementing.
			putValue(NAME,"添加选择题");
			//putValue(SMALL_ICON,new ImageIcon(getClass().getResource("images/insert.gif")));
			putValue(SHORT_DESCRIPTION,"添加一条新的添加选择题试题信息!");
			putValue(LONG_DESCRIPTION,"添加一条新的添加选择题试题信息!");
			putValue(MNEMONIC_KEY,new Integer('I'));
		}
		//display window in which user can input information.
		public void actionPerformed(ActionEvent e){
			//create new internal window ~~
			questionType="s";
			TestQuestionEntry question=new TestQuestionEntry();
			SingleTestQuestionEntryFrame entryFrame=creatSingleTestQuestionEntryFrame();
			entryFrame.setTestQuestionEntry(question);
			question.setType(questionType);
			desktop.add(entryFrame);
			entryFrame.setVisible(true);
		}		
	}
	private class TruefalseInsertAction extends AbstractAction{
		/**
		 * 	private inner class defines action that enables users
	     *  to input new test question.if user want to save the question information
	     *  then you must invoke the savaAction command.
		 */
		private static final long serialVersionUID = 1L;
		//set up action's id,difficulty,timelimited,content,answer and score.
		public TruefalseInsertAction(){
			//inner method for implementing.
			putValue(NAME,"添加判断题");
			//putValue(SMALL_ICON,new ImageIcon(getClass().getResource("images/insert.gif")));
			putValue(SHORT_DESCRIPTION,"添加一条新的添加判断题试题信息!");
			putValue(LONG_DESCRIPTION,"添加一条新的添加判断题试题信息!");
			putValue(MNEMONIC_KEY,new Integer('I'));
		}
		//display window in which user can input information.
		public void actionPerformed(ActionEvent e){
			//create new internal window ~~
			questionType="t";
			TestQuestionEntry question=new TestQuestionEntry();
			SingleTestQuestionEntryFrame entryFrame=creatSingleTestQuestionEntryFrame();
			entryFrame.setTestQuestionEntry(question);
			question.setType(questionType);
			desktop.add(entryFrame);
			entryFrame.setVisible(true);
		}		
	}	
	private class BlankInsertAction extends AbstractAction{
		/**
		 * 	private inner class defines action that enables users
	     *  to input new test question.if user want to save the question information
	     *  then you must invoke the savaAction command.
		 */
		private static final long serialVersionUID = 1L;
		//set up action's id,difficulty,timelimited,content,answer and score.
		public BlankInsertAction(){
			//inner method for implementing.
			putValue(NAME,"添加填空题");
			//putValue(SMALL_ICON,new ImageIcon(getClass().getResource("images/insert.gif")));
			putValue(SHORT_DESCRIPTION,"添加填空题");
			putValue(LONG_DESCRIPTION,"添加填空题");
			putValue(MNEMONIC_KEY,new Integer('I'));
		}
		//display window in which user can input information.
		public void actionPerformed(ActionEvent e){
			//create new internal window ~~
			questionType="b";
			TestQuestionEntry question=new TestQuestionEntry();
			SingleTestQuestionEntryFrame entryFrame=creatSingleTestQuestionEntryFrame();
			entryFrame.setTestQuestionEntry(question);
			question.setType(questionType);
			desktop.add(entryFrame);
			entryFrame.setVisible(true);
		}		
	}
	private class SaveAction extends AbstractAction{
		/** inner class defines an action that can save new or
		 * update information input.
		 */
		private static final long serialVersionUID = 1L;
		//set up action's id,difficulty,timelimited,content,answer and score.
		public SaveAction(){
			//inner method for implementing.
			putValue(NAME,"保存输入信息");

⌨️ 快捷键说明

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