FileDocCategorySizeDatePackage
QuizCardReader.javaAPI DocExample4126Sat Jan 08 12:06:56 GMT 2005None

QuizCardReader

public class QuizCardReader extends Object

Fields Summary
private JTextArea
display
private JTextArea
answer
private ArrayList
cardList
private QuizCard
currentCard
private Iterator
cardIterator
private JFrame
frame
private JButton
nextButton
private boolean
isShowAnswer
Constructors Summary
Methods Summary
public voidgo()


        frame = new JFrame("Quiz Card Player");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel mainPanel = new JPanel();
        Font bigFont = new Font("sanserif", Font.BOLD, 24);

        display = new JTextArea(9,20);
        display.setFont(bigFont);
        display.setLineWrap(true);
        display.setWrapStyleWord(true);
        display.setEditable(false);
       
        JScrollPane qScroller = new JScrollPane(display);
        qScroller.setVerticalScrollBarPolicy(
              ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        qScroller.setHorizontalScrollBarPolicy(
              ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
      
        nextButton = new JButton("Show Question");
        
        mainPanel.add(qScroller);
        mainPanel.add(nextButton);
        nextButton.addActionListener(new NextCardListener());
        JMenuBar menuBar = new JMenuBar();
        JMenu fileMenu = new JMenu("File");
        
        JMenuItem loadMenuItem = new JMenuItem("Load card set");
            
        loadMenuItem.addActionListener(new OpenMenuListener());
            
        fileMenu.add(loadMenuItem);
        
        menuBar.add(fileMenu);
        frame.setJMenuBar(menuBar);
    
        frame.getContentPane().add(BorderLayout.CENTER, mainPanel);
        frame.setSize(500,600);
        frame.setVisible(true);        
    
private voidloadFile(java.io.File file)

      cardList = new ArrayList();
      try {
         BufferedReader reader = new BufferedReader(new FileReader(file));
         String line = null;
         while ((line = reader.readLine()) != null) {
            makeCard(line);
         }
         reader.close();

      } catch(Exception ex) {
          System.out.println("couldn't read the card file");
          ex.printStackTrace();
      }

     // now time to start
     cardIterator = cardList.iterator();
     showNextCard();
   
public static voidmain(java.lang.String[] args)

       QuizCardReader qReader = new QuizCardReader();
       qReader.go();
    
private voidmakeCard(java.lang.String lineToParse)

   
      StringTokenizer parser = new StringTokenizer(lineToParse, "/");
      if (parser.hasMoreTokens()) {
         QuizCard card = new QuizCard(parser.nextToken(), parser.nextToken());
         cardList.add(card);
      }
   
private voidshowNextCard()

        currentCard = (QuizCard) cardIterator.next();
        display.setText(currentCard.getQuestion());
        nextButton.setText("Show Answer");
        isShowAnswer = true;