GUIs


GUIs

Outer.java - buttons and actionlisteners
MessageDialogExample.java

Bunny.java
BunnyGUI.java

 

Read D&D 12, 22

Classwork


Create a class Account which has instance variables for the account number and the current balance.

Create a class BankGUI that inherits from JFrame.  (This time we will hand code the GUI --  it is okay if your GUI is not beautiful.)

Give BankGUI  an instance variable of type Account. and start it off with a random account number and balance 0. 

You can do most of your setup in the constructor, or put it in other methods called by the constructor.  Remember things like setting the layout, packing, and making visible, these will look very much like the example code).

To make the GUI come up, add a main in BankGui that just creates a BankGui object (calling the constructor).

In the JFrame, put two labels which show the values for the account number and balance.  Any time the instance variable for balance in the Account is changed, remember you will need to update the corresponding label as well.

Add a button with the text "Quick Deposit". When the user clicks the button, deposit $20 to the Account's balance.  

Add a button with the text "Quick Cash". When the user clicks the button, withdraw $10 from the Account's balance only if the balance is at least that high. If the balance is not high enough, leave the balance alone but use JOptionPane to tell the user they don't have enough money. 

[EC] To Account, add an instance variable interestRate defaulting to 0.20%.  To the GUI add a button "Interest Payment" which increases the balance using the interest rate.

[EC] At the beginning of the program and any time after a withdrawal when there is less than $10 in the account, set the text on the Quick Cash button to say "Insufficient Funds".  Any time there is more than $10 in the account, set the text on the button to "Quick Cash" instead. Think carefully about when you should check to see whether the balance has changed enough to change this in each direction.

[EC]  Make Account Serializable.  Add a button to the GUI that serializes the account to a file.  When the program begins, try to set up the account by loading a previously serialized account from a file; if this fails for any reason, start a new account with the default values instead. (The program always uses the same filename (in the top of the project directory) for this, it doesn't need to ask the user for the file name).  {If doing both this and the previous EC, this may affect whether the button should start as "Insufficient Funds" or not}