And the passing of parameters.
Here is the same app using GUIs coded in two different ways – the first has no OOP programming while the second does. The first is a one-class program. The second is a two-class program.
In your grade 12 PAT project you have to use OOP principals i.e. your working code must be separate from your GUIs – behind your action buttons you have “getter” and “setter” type code, but the real logic must be in various methods in a manager class i.e. you must call methods from your action buttons.
In the program above the name, the random numbers, the community service and the prize are coded behind the “Lucky Numbers” button. In this non OOP version, no passing of parameters is needed.
Here is the code for this version
This version shown above is a two class program. It has a UI class with a main method and a JFrameForm. It has a separate manager class where the methods are stored. The action buttons on the GUI call the methods (and do some getting and setting). This version also has some defensive coding i.e. a full name is compulsory, and the buttons have to be pressed in the right order. The four separate buttons are able to demonstrate the passing of parameters between methods and classes.
Here is the code (both classes)
NOTE: Much of the scary code in this version is auto- generated by the drag-and-drop JFrameForm class – see other posts on how to generate GUIs for your PAT using JFrameForm