/* * @(#)QuestionEngine.java 0.0.1 99/07/08 * * Copyright (c) 1999 by Grant Olds. All rights reserved. */ package exercise.engine; import java.io.*; import java.awt.*; import java.net.*; import java.util.*; import javax.swing.*; /** * QuestionEngine is the base class that parses in a file created * by the QuestionWriter application and creates a new question * module according to the type a file that is read in. The question * modules that can be created are Multiple Choice module, Number module, * and Text module. *

* WLW (07/08/99): I removed unnecessary fields and methods, added * readImage(), and cleaned up the source code. * * @version 0.0.1 07/08/99 * @author Grant Olds * @author Willie Wheeler */ public class QuestionEngine extends JApplet { /** * The init() method reads in the specified file name from the * html tag, tries to open the file, then checks to see what type of * module the file wants to create. Depending on the module it wants to * create, it calls the correct file parser to write file data to the * proper content file. Finally the correct module creator is called to * produce a module. */ public void init() { URL source; String file = "test.txt"; StringTokenizer st; String read = new String(); StringBuffer type = new StringBuffer(); String checkType = new String(); setSize(432, 600); // getContentPane().setBackground ( new Color ( 255, 204, 102 ) ); getContentPane().setLayout (new BorderLayout()); // Try to open the file. try { source = new URL ( getCodeBase(), file ); // Read in the file. BufferedReader in = new BufferedReader( new InputStreamReader(source.openStream())); String tmp; while ((tmp = in.readLine()) != null) { read += tmp; read += " "; } } catch(IOException ioe) { System.out.println("Error: " + ioe); } QuestionModuleWrapper moduleWrapper = new QuestionModuleWrapper( read, readImage("hintDown"), readImage("hintOff"), readImage("hintRoll"), readImage("hintUp"), readImage("submitDown"), readImage("submitOff"), readImage("submitRoll"), readImage("submitUp"), readImage("attention").getImage(), readImage("correct").getImage(), readImage("incorrect").getImage() ); getContentPane().add (moduleWrapper, BorderLayout.CENTER); } /** * Convenience method to read a gif from disk. * * @return image with the given filename, minus the '.gif' extension. */ private ImageIcon readImage(String filename) { return new ImageIcon(getImage(getCodeBase(), "resources/question_engine/images/" + filename + ".gif") ); } }