/*
*/
import java.awt.*;
import java.util.*;
import java.applet.*;
import java.awt.event.*;
public class FlashCard extends Applet {
PanelNumber p_Numbers;
ScorePanel p_Score;
public void init() {
p_Score = new ScorePanel();
p_Numbers = new PanelNumber(p_Score);
this.setLayout(new BorderLayout());
p_Score.setLayout(new GridLayout(2,1,10,10));
add("West",p_Numbers);
add("Center",p_Score);
}
public boolean mouseDown(Event evt, int x, int y) {
System.out.println("X: "+x+" Y: "+y);
p_Numbers.repaint();
return true;
}
} // End Class FlashCard
//////////////////
class PanelNumber extends Panel {
int problemType;
String s, userS;
int numA, numB, solution, appX, appY, xNum, yNum;
Dimension size;
ScorePanel p_Score;
public PanelNumber(ScorePanel p_Score) {
this.p_Score = p_Score;
appX = this.size().width;
appY = this.size().height;
appX = 320;
appY = 200;
size = new Dimension (appX,appY);
xNum = 20;
yNum = 119;
setBackground(Color.white);
problemType = 0;
userS = "?";
nextProblem();
}
public void nextProblem() {
switch((p_Score.d.getSelectedIndex())) {
case 0:
addProblem();
break;
case 1:
subProblem();
default:
} // End switch
}
public void paint(Graphics g) {
drawCard(g);
g.setFont(new Font("ARIAL",Font.BOLD,48));
g.setColor(Color.black);
g.drawString(s+userS,xNum,yNum);
}
public void drawCard(Graphics g) {
g.setColor(new Color(190,190,240));
for (int i=40;i numB){
s = ""+numA+" - "+numB+" = ";
numB = numB*-1;
}
else{
s = ""+numB+" - "+numA+" = ";
numA = numA*-1;
}
solution = Math.abs(numA + numB);
}
public boolean keyDown(Event evt, int key) {
// Evaluate
if (key == '\n') {
if (userS.equals("?"))
System.out.println("Nothing");
else {
if (userS.equals(""+solution)) {
p_Score.setCorrect();
userS = "?";
nextProblem();
} else {
// userS = "?";
p_Score.setTries();
}
} // End else
}
if (key >= '0' && key <= '9') {
if (userS.equals("?"))
userS = ""+(char)key;
else
userS += (char)key;
}
if (key == Event.DELETE || key == 8) {
userS = "?";
}
repaint();
return true;
} // End key
public Dimension getMinimumSize() {
return size;
}
public Dimension getPreferredSize(){
return size;
}
} // End Class PanelNumber
/////////////////////////////////
class ScorePanel extends Panel {
Image back;
Panel a,b,c;
int correct, try2;
TextField ta1 = new TextField(5);
TextField ta2 = new TextField(5);
TextField ta3 = new TextField(5);
Choice d = new Choice();
Choice e = new Choice();
public ScorePanel () {
try2 = 0;
correct = 0;
a = new Panel();
a.setLayout(new GridLayout(2,2,10,10));
b = new Panel();
b.setLayout(new BorderLayout());
c = new Panel();
c.setLayout(new GridLayout(3,2,10,10));
d.addItem("Addition");
d.addItem("Subtraction");
// d.addItem("Multiplication");
// d.addItem("Division");
// d.addItem("Random");
e.addItem("1");
e.addItem("5");
e.addItem("10");
e.addItem("20");
a.add(new Label("Problem Type"));
a.add(d);
a.add(new Label("# of Problems"));
a.add(e);
b.add("Center",a);
b.add("South",new Button("Start Over"));
add(b);
c.add(new Label("# Correct: "));
c.add(ta1);
c.add(new Label("# Missed: "));
c.add(ta2);
c.add(new Label("Total #: "));
c.add(ta3);
add(c);
}
public void setCorrect() {
correct++;
ta1.setText(""+correct);
ta3.setText(""+(try2+correct));
}
public void setTries() {
try2++;
ta2.setText(""+try2);
ta3.setText(""+(try2+correct));
}
} // End Class ScorePanel