This document identifies what each class does, and what their methods do in:
- MainPanel.java
- OpenExam.java
I have commented these java documents already so that you can all just go through the classes and you will see
these comments within the code.
Class OpenExam:
![](openExam.JPG)
- OpenExam(): Sets up the initial GUI that asks user for exam. Has a button panel with Simulate and Close panel
- afterSetText(): this requests focus for the simulate button. This is called from the setText() method in the JBrowseField class.
![](aftersettext.JPG)
- simulate() tries to run the method run() which creates a new exam controller passing in the file created in the constructor and a new windowclosinglistener it also calls the method showMainPanel. If the file cannot be opened a message prints "Error_loading_the_JPilotExam_file"
- CreateFileFilters(): this returns a list of FileFilters. This class uses the .add method of the List object
Called in the afterSetText() method
- showMainPanel(): opens up the main panel frame in a try ctach statement. An error message is shown if the main Panel cannot shown. Then the startSimulation() method is called.
- startSimulation(): This method calls the examcontroller.start()
- updateExamDetails(String examDetails): this method is passed in a string which it returns at the end. A new JPSExam is initialized using the getExam() method in the ExamController class. It then fills in all the properties of the exam extracted from the ExamController which is the exam we wish to run. Finally, it returns the examDetails string.
- updateExamInstructions(String examInstructions): pretty much does the same thing as the previous method, it fills in the instructions for the exam with the instructions from the examController exam. It then returns this string.
- Both of these methods use StringUtilities.replace()
- private final void shutdown(): This creates a string buffer, appends a few senteces to it and then prints that buffer and exits.
- actionPerformed(ActionEvent event): In this method the command is read from the event and if it is the simulate button that was clicked, if the browseField is not null, then whatever file is in there is what is put into our instance of File called file. If file is null then and error message tells the user to enter a valid file. If file is not null then the frame we're working with disappears and the simulate() method is called.
In the case that the command read from the event is not equal to Simulate, then it must be the close button and the shutdown() method is called.
MainPanelEventHandler class
- actionPerformed(): If the even command == next then the next button was pressed and the page index increases by 1. Then there's a switch statement for the 2 preliminary pages 1: the Exam Details and 2: Exam Instructions
For both cases, a string is initialized using the StringUtilities.fromFile() method. Then the updateExamDetails() or updateExamInstructions() methods are called. Finally, the page text is set to that string.
- Because this is all in a try-catch statement if any of it fails, an error message will print. Within the switch statement, for case pageIndex=2, the mainPanel.setStart() method is called.
- Within the same actionPerformed() method if the event command == close then the shutdown() method is called.
- If the even command is not close or next then the program moves on, hides the main panel frame and calls the
- class Exam Controller: An exam object is created by passing in a File and a WindowListener. This class keeps track of the timer, the questions, the marked questions, the previous and the next questions etc. it also shows the review panel, the staistics, and it has it's own shutdown method.
- examController.start(): calls the doTimerEvent(), sets the exam frame visible and starts the timer.
- doTimerEvent(): this method shows the remaining time and checks that time >0 or it stops the timer and displays a message.
Class MainPanel:
![](mainPanel.JPG)
- This class extends JPanel.
- Its constructor takes in an ActionListener and a WindowListener.
- It then creates the buttons Next and Close and assigns the actionListener to them. It also assigns a key (N o C) so that you can just press those instead of clicking the actual buttons. (mnemonics)
- Then panels for these buttons are created and added to a bigger panel.
- A JHTMLPane is created. JHTMLPane is a class that extends JTextPane. The setEditable() method is called to set the text pane to noneditable. Then a scroll panel is created passing in the JHTMLPane above so that the text pane is wrapped by the scroll panel.
- A frame is then initialized and the buttons' panel and the scroll panel are added to its contentpane.
- The DefaultCloseOperation is set to DO_NOTHING_ON_CLOSE so that the windowListener can do its job.
- The showFrame() and hideFrame() make the window visible or not. The getFrame() method simply returns that frame.
- setPageText(): this method is passed in a string and basically displays it on the text pane or JHTMLPane in the format previously specified in the JHTMLPane class(text/html).
- setStart(): this method is called in the OpenExam class when the page ==2 (instructions page), and it changes the Next button test to Start and it's mnemonic to S.