[sword-cvs] r59 - trunk/app/src/org/crosswire/flashcards
Apache
apache at crosswire.org
Wed Sep 22 12:30:45 MST 2004
Author:
Date: 2004-09-22 12:30:45 -0700 (Wed, 22 Sep 2004)
New Revision: 59
Modified:
trunk/app/src/org/crosswire/flashcards/QuizPane.java
trunk/app/src/org/crosswire/flashcards/SetupPane.java
Log:
Added a "No Multiple Choice" option.
Modified: trunk/app/src/org/crosswire/flashcards/QuizPane.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/QuizPane.java 2004-09-22 00:50:38 UTC (rev 58)
+++ trunk/app/src/org/crosswire/flashcards/QuizPane.java 2004-09-22 19:30:45 UTC (rev 59)
@@ -36,6 +36,7 @@
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
+import javax.swing.JOptionPane;
import java.awt.*;
@@ -244,47 +245,56 @@
{
currentWord = w;
wordText.setText(w.getSide(!setupPane.isFlipped()));
- Vector choices = (Vector) words.clone();
- choices.remove(w);
-
- // randomly pick answers
- boolean flipped = setupPane.isFlipped();
- List picks = new ArrayList();
- picks.add(createAnswerEntry(w.getSide(flipped)));
- int size = words.size();
- while (picks.size() < Math.min(10, size))
+ if(setupPane.isNoMultipleChoice())
{
- int c = (int) (Math.random() * choices.size());
- WordEntry wc = (WordEntry) choices.get(c);
- String answer = wc.getSide(flipped);
+ choicesPanel.invalidate();
+ choicesPanel.validate();
+ choicesPanel.repaint();
+ }
+ else
+ {
+ Vector choices = (Vector) words.clone();
+ choices.remove(w);
- // some times two different word have the same answer
- if (!picks.contains(answer))
+ // randomly pick answers
+ boolean flipped = setupPane.isFlipped();
+ List picks = new ArrayList();
+ picks.add(createAnswerEntry(w.getSide(flipped)));
+ int size = words.size();
+ while (picks.size() < Math.min(10, size))
{
- picks.add(createAnswerEntry(answer));
- choices.remove(wc);
+ int c = (int) (Math.random() * choices.size());
+ WordEntry wc = (WordEntry) choices.get(c);
+ String answer = wc.getSide(flipped);
+
+ // some times two different word have the same answer
+ if (!picks.contains(answer))
+ {
+ picks.add(createAnswerEntry(answer));
+ choices.remove(wc);
+ }
}
+ // Now randomize these answers. To do this we swap the first one
+ // with another.
+ int c = (int) (Math.random() * picks.size());
+ // If we have selected something other than ourselves.
+ if (c > 0)
+ {
+ picks.add(0, picks.remove(c));
+ picks.add(c, picks.remove(1));
+ }
+ Iterator iter = picks.iterator();
+ while (iter.hasNext())
+ {
+ choicesPanel.add((Component) iter.next());
+ }
+ wrong = 0;
+ shownAnswer = false;
+ updateStats();
+ choicesPanel.invalidate();
+ choicesPanel.validate();
+ choicesPanel.repaint();
}
- // Now randomize these answers. To do this we swap the first one
- // with another.
- int c = (int) (Math.random() * picks.size());
- // If we have selected something other than ourselves.
- if (c > 0)
- {
- picks.add(0, picks.remove(c));
- picks.add(c, picks.remove(1));
- }
- Iterator iter = picks.iterator();
- while (iter.hasNext())
- {
- choicesPanel.add((Component) iter.next());
- }
- wrong = 0;
- shownAnswer = false;
- updateStats();
- choicesPanel.invalidate();
- choicesPanel.validate();
- choicesPanel.repaint();
}
@@ -303,8 +313,9 @@
{
percent = (int) ((((float) (totalAsked - totalWrong)) / (float) totalAsked) * (float) 100);
}
- wCount.setText(Integer.toString(notLearned.size()) + " | " + Integer.toString(totalAsked - totalWrong) + "/" + Integer.toString(totalAsked) + " ("
- + Integer.toString(percent) + "%)");
+ wCount.setText(Integer.toString(notLearned.size()) + " | " +
+ Integer.toString(totalAsked - totalWrong) + "/" + Integer.toString(totalAsked) +
+ " (" + Integer.toString(percent) + "%)");
}
@@ -366,21 +377,51 @@
void showAnswerButton_actionPerformed(ActionEvent e)
{
- if (!shownAnswer)
+ if (setupPane.isNoMultipleChoice())
{
- showAnswer();
- return;
+ ++totalAsked;
+ String dialogString = new String(currentWord.getSide(!setupPane.isFlipped())+"\n"+
+ currentWord.getSide(setupPane.isFlipped())+"\n"+
+ "Did You Get It Right?\n");
+ int choice = JOptionPane.showConfirmDialog(this,dialogString,"Result",
+ JOptionPane.YES_NO_OPTION);
+ if (JOptionPane.YES_OPTION == choice)
+ {
+ notLearned.remove(currentWord);
+ }
+ else
+ {
+ ++totalWrong;
+ }
+ updateStats();
+ if (notLearned.size() > 0)
+ {
+ showRandomWord(currentWord);
+ }
+ else
+ {
+ wordText.setText("-=+* Great! *+=-");
+ statusBar.setText("Nice Job! You've mastered all " + words.size() + " words!");
+ }
}
- int next = notLearned.indexOf(currentWord) + 1;
- if (next == 0)
+ else
{
- return;
+ if (!shownAnswer)
+ {
+ showAnswer();
+ return;
+ }
+ int next = notLearned.indexOf(currentWord) + 1;
+ if (next == 0)
+ {
+ return;
+ }
+ if (next >= notLearned.size())
+ next = 0;
+ deleteChildren(choicesPanel);
+ showWord((WordEntry) notLearned.get(next));
+ showAnswer();
}
- if (next >= notLearned.size())
- next = 0;
- deleteChildren(choicesPanel);
- showWord((WordEntry) notLearned.get(next));
- showAnswer();
}
}
Modified: trunk/app/src/org/crosswire/flashcards/SetupPane.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/SetupPane.java 2004-09-22 00:50:38 UTC (rev 58)
+++ trunk/app/src/org/crosswire/flashcards/SetupPane.java 2004-09-22 19:30:45 UTC (rev 59)
@@ -44,6 +44,7 @@
private LessonPane lessonPanel = new LessonPane();
private LessonSetPane lessonSetPanel = new LessonSetPane();
private JCheckBox flipped = new JCheckBox("Flip the Flash Cards");
+ private JCheckBox noMultipleChoice = new JCheckBox("No Multiple Choice");
//Construct the frame
public SetupPane()
@@ -62,6 +63,11 @@
{
return flipped.isSelected();
}
+
+ public boolean isNoMultipleChoice()
+ {
+ return noMultipleChoice.isSelected();
+ }
public Iterator iterator()
{
@@ -129,8 +135,9 @@
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
- "Show the backs of the Flash Cards for the test: "));
+ "Quiz Options: "));
panel.add(flipped);
+ panel.add(noMultipleChoice);
add(panel, BorderLayout.SOUTH);
}
More information about the sword-cvs
mailing list