Methods Summary |
---|
public void | go()
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 void | loadFile(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 void | main(java.lang.String[] args)
QuizCardReader qReader = new QuizCardReader();
qReader.go();
|
private void | makeCard(java.lang.String lineToParse)
StringTokenizer parser = new StringTokenizer(lineToParse, "/");
if (parser.hasMoreTokens()) {
QuizCard card = new QuizCard(parser.nextToken(), parser.nextToken());
cardList.add(card);
}
|
private void | showNextCard()
currentCard = (QuizCard) cardIterator.next();
display.setText(currentCard.getQuestion());
nextButton.setText("Show Answer");
isShowAnswer = true;
|