wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Rerun an app Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Rerun an app" Watch "Rerun an app" New topic
Author

Rerun an app

Adam Burda
Ranch Hand

Joined: Jul 19, 2011
Posts: 40
Hi all,
Im making an app that does time tables for my kid.
I can not find away to rerun the app if the answer is right, after clicking the JButton.
Here is my code. And thank you for your help.
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

You would have to put the code for generating new multiplication questions in a separate method.

The code you have does pretty much everything in constructor. What you should do in a constructor is just initialize GUI components and put them on your panel. Labels for operands would be initialized with empty strings, since operands will be chosen in a separate method you are about to define.

Then you define another method (say generateNewMultiplicationQuestion()) that would contain the logic for picking random numbers from those arrays (the code you already have) and once you pick the numbers you would just setText() method to set them to labels:

This method can then be invoked each time you want to generate a new question after the answer to the current one is correct:

If you want the question to be initialized as soon as you run the application, than you would invoke the above method once at the end of your constructor.

Also note what happens when you click the button without providing an answer (or providing text as an answer).


The quieter you are, the more you are able to hear.
Adam Burda
Ranch Hand

Joined: Jul 19, 2011
Posts: 40
Thank you. It works now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Rerun an app
 
Similar Threads
Trouble executing(actionlistener) the swing applet properly in html
Clip Board Problem
Clip Board Problem
Need help with displaying data in a JTable
JTable ........