Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
You can always have a reference to the QuizCardBuilder instance in the GUI components and when ever you click on button you can invoke the addToList (supposing this adds the object to the list) method of the QuizCardBuilder instance to add the QuizCard object.
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
Luigi Plinge wrote:But if the QuizCardBuilder is a variable of the CardBuilderFrame, how do I invoke its methods from the buttons on the CardBuilderPanel? I need to use both the menu items in the frame and the buttons and text fields on the panel.
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
Luigi Plinge wrote:But it will then be 2 different instances, so if I try to use a method to save it from the frame, it won't contain the questions/answers that have been added on the panel.
Plus it doesn't make sense to have it as an instance variable. QuizCardBuilder is the application itself and creates the frame and panel - it doesn't belong to the frame or panel.
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
After 0.1 seconds, Controller #1 calls Jemaine
After 0.4 seconds, Brahbra calls Murray
...Murray explodes!
After 0.4 seconds, Murray calls Bret
After 0.9 seconds, Murray calls Brahbra
...Brahbra explodes!
After 1.1 seconds, Brahbra calls Jemaine
After 1.1 seconds, Controller #2 calls Bret
After 1.3 seconds, Bret calls Brahbra
...Brahbra explodes!
After 1.4 seconds, Murray calls Bret
After 1.9 seconds, Jemaine calls Murray
...Murray explodes!
After 2.0 seconds, Controller #1 calls Murray
...Murray explodes!
After 2.1 seconds, Controller #2 calls Bret
After 2.4 seconds, Bret calls Controller #2
After 2.7 seconds, Brahbra calls Jemaine
After 2.9 seconds, Murray calls Brahbra
...Brahbra explodes!
After 3.1 seconds, Murray calls Controller #1
Consider Paul's rocket mass heater. |