• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Rerun an app

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Adam Burda
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you. It works now.
 
reply
    Bookmark Topic Watch Topic
  • New Topic