How can i get my program to wait until the user inputs something into a textfield before my program checks if it is equal.
When i searched online I only saw results for Jtextfields not textfields and idk know if the same things will work for both. Also they were all really complicated and beyond my level. Is there a simpler way or someone willing to explain the more complicated way. Below is the necessary code.
The textfield is called Answer and i assign ananswer to the input, then compare it to realanswer
public void getquestion (int level, Graphics g)
{
Answer.setVisible (true);
double realanswer;
super.paint (g);
int shape = 1;
if (shape == 1)
{
double radius = 0;
double height = 0;
double diameter = 0;
double volume = 0;
double surfacearea = 0;
double radius2 = 0;
double height2 = 0;
realanswer = 0;
switch (level)
{
case 1:
g.drawImage (cylinder, 100, 150, this);
radius = 1 + (int) (Math.random () * 10);
height = 1 + (int) (Math.random () * 10);
g.drawString ("The Height of the Cylinder is " + height, 400, 100);
g.drawString ("The Radius of the Cylinder is " + radius, 400, 120);
g.drawString ("What is the volume of the Cylinder?", 100, 140);
realanswer = Math.round(Math.PI * radius * radius * height);
break;
default:
height2 = 1 + (Math.random () * 100);
radius2 = 1 + (Math.random () * 100);
height = height2 + (Math.random () * 100);
radius = radius2 + (Math.random () * 100);
break;
}
if (realanswer == ananswer)
{
g.drawImage (mathmeme1, 100, 150, this);
}
else
{
g.drawImage (fail1, 100, 150, this);
}
}
}
public void actionPerformed (ActionEvent evt)
{
ananswer = Integer.parseInt (Answer.getText ());
}