Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
at BankApplication$1ButtonListener.actionPerformed(BankApplication.java:51)
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Scanner;
import javax.swing.JFrame;
//This program provides an interface for the user to make us of the Bank class'
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
//functionality.
public class BankApplication implements ActionListener {
private static JTextField depositAccount;
private static JTextField depositAmount;
private static JPanel dpanel;
private static JLabel options;
private static JTextField userchoice;
private static JFrame bye;
private static JLabel byetext;
public static void main (String[] args){
//A scanner for taking input from user
Scanner in = new Scanner(System.in);
//A Bank object to hold accounts and perform operations
Bank theBank = new Bank();
//A String for holding user input
String choice = new String();
//This while loop just keeps going back to the main menu until the user
//chooses option 6, which is to exit
JFrame bankframe = new JFrame();
bankframe.setLayout(new FlowLayout());
class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
actionPerformed(e);
}
}
ButtonListener listen = new ButtonListener();
bankframe.setSize(600, 600);
bankframe.setTitle("CAS BANK");
bankframe.setVisible(true);
dpanel = new JPanel();
bankframe.add(dpanel);
options = new JLabel("1. Make a deposit " +
"2. Make a withdrawal " +
"3. Check an account balance " +
"4. Create a new account " +
"5. See a list of all accounts " +
"6. Exit the program");
bankframe.add(options);
userchoice= new JTextField("Pick your option");
userchoice.addActionListener(listen);
bankframe.add(userchoice);
while (!(choice.equals("6"))){
//Printing the main menu
System.out.println("1. Make a deposit");
System.out.println("2. Make a withdrawal");
System.out.println("3. Check an account balance");
System.out.println("4. Create a new account");
System.out.println("5. See a list of all accounts");
System.out.println("6. Exit the program");
System.out.println("Select an option, enter its number, and " +
"press enter:");
//Take choice input from user
choice = in.next();
//Make some space after the input to reduce clutter
System.out.println("\n");
//User chooses 1 to deposit
if (choice.equals("1")){
depositAccount= new JTextField("Please enter the bank account number:");
dpanel.add(depositAccount);
//Get account number
System.out.println("Please enter the bank account number:");
int accountNumber = in.nextInt();
//Checks to make sure account exists
if (theBank.checkForAccount(accountNumber)){
//Get amount to deposit
depositAmount= new JTextField("Please enter how much you want to deposit:");
dpanel.add(depositAmount);
System.out.println("Please enter the deposit amount using only digits and a decimal point:");
double depositAmount = in.nextDouble();
//Make the deposit
theBank.makeDeposit(accountNumber, depositAmount);
//Show updated balance
System.out.printf("Your account balance is: $%,.2f" ,
theBank.checkBalance(accountNumber));
}
//What to do if the account does not exist
else
System.out.println("No such account, returning to main " +
"menu");
}
//User chooses 2 to withdraw
else if (choice.equals("2")){
//Get the account number
System.out.println("Please enter the bank account number:");
int accountNumber = in.nextInt();
//Checks to make sure account exists
if (theBank.checkForAccount(accountNumber)){
//Get withdrawal amount
System.out.println("Please enter the amount to withdraw using only digits and a decimal point:");
double withdrawalAmount = in.nextDouble();
//Make withdrawal
theBank.makeWithdrawal(accountNumber, withdrawalAmount);
//Show new balance
System.out.printf("Your account balance is: $%,.2f" ,
theBank.checkBalance(accountNumber));
}
//What to do if the account does not exist
else
System.out.println("No such account, returning to main " +
"menu");
}
//User chooses 3 to check the balance of an account
else if (choice.equals("3")){
//Get the account number
System.out.println("Please enter the bank account number:");
int accountNumber = in.nextInt();
//Checks to make sure account exists
if (theBank.checkForAccount(accountNumber)){
//Show the balance
System.out.printf("Your account balance is: $%,.2f" ,
theBank.checkBalance(accountNumber));
}
//What to do if the account does not exist
else
System.out.println("No such account, returning to main " +
"menu");
}
//User chooses 4 to create a new account
else if (choice.equals("4")){
System.out.println("Please enter the initial balance:");
double initialBalance = in.nextDouble();
if (initialBalance<100){
System.out.println("Initial deposit must be 100 or more");
}
else if(initialBalance>=100){
//Create the new account and get its number
int newAccountNumber = theBank.addAccount(initialBalance);
//Show results
System.out.println("New account created");
System.out.println("Account number is: " +
newAccountNumber);
System.out.printf("Balance is: $%,.2f" ,
theBank.checkBalance(newAccountNumber));}
}
//User chooses five to print table of accounts
else if (choice.equals("5")){
//Get the list of accounts
String[][] accountList = theBank.getAccountList();
//Making the frame object
JFrame frame = new JFrame();
//Making the frame of appropriate size to hold all accounts
//410 Wide to hold the two 200 wide columns and the 5 wide
//border
//Minimum 60 tall, add 25 to make room for each account
frame.setSize(410, 60 + (25 * (accountList.length)));
frame.setTitle("Account List");
//This makes it so that the frame is disposed of when the user
//closes it, which allows the program to exit when the user
//chooses option 6 (exit). Without this, the program keeps
//runing because the frame is still hiding somewhere.
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
//Make a new account table
AccountTableComponent accountTable = new
AccountTableComponent(accountList);
//Add it to the frame
frame.add(accountTable);
//Show the frame
frame.setVisible(true);
}
//User chooses six to exit
else if (choice.equals("6")){
bye=new JFrame("Thank you");
bye.setSize(200,200);
bye.setVisible(true);
byetext = new JLabel("Thank you for using CAS Bank");
bye.add(byetext);
bye.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
//If they enter anything else, it is an invalid choice, start over
else {
System.out.println("Invalid option, please try again:");
}
//Make some space before the main menu so the screen looks cleaner
System.out.print("\n\n");
}
}
public void actionPerformed(ActionEvent ae) {
System.out.println(userchoice.getText());
}
}

New Topic/Question
Reply




MultiQuote





|