Hello everyone. I have been working on this program for over a week. I really need some help getting this done. I was able to get the math.random to work but when I run my program as an applet I have a text box that I dont know how to link to my button. Can someone please show me how to do this?
// When this is finished it will tell you if your answer is right or incorrect.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import java.util.*;
public class JMathfun extends JApplet implements ActionListener {
int number1 = 1 + ( int )( Math.random() * 9 );
int number2 = 1 + ( int )( Math.random() * 9 );
Container con = getContentPane();
JLabel math = new JLabel(" What is : " + number1 + " TIMES " + number2);
JTextField userin = new JTextField(2);
JButton checkanswer = new JButton("Check Answer");
JLabel correct = new JLabel("Correct");
JLabel tryagain = new JLabel("Sorry, Please try again");
int rightanswer = number1 * number2;
public void init() {
con.add(math);
con.add(userin);
con.add(checkanswer);
con.setLayout(new FlowLayout());
}
public void actionPerformed(ActionEvent e)
{
con.add(tryagain);
con.add(correct);
}
}
Thanks for the help in advance.
Erich