Question
I need help being able to login and put in a password for my GUI also my GUI does not want to run with the
I need help being able to login and put in a password for my GUI also my GUI does not want to run with the other classes My Main and Account
import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.lang.Integer; public class GuiAccTest extends Frame implements ActionListener
{ Label lab=new Label(" "); Label lab1=new Label(" "); TextField t[]=new TextField [4]; Label l[]=new Label [4]; Button but=new Button("Create Account"); Button but1=new Button("Test Account"); BankAccount b; GuiAccTest() { addWindowListener(new NewWindowAdapter()); setLayout(new GridLayout(2,0)); Panel p=new Panel(); Panel p1=new Panel(); but.addActionListener(this); but1.addActionListener(this); p.setLayout(new GridLayout(5,2)); p1.add(lab1); p1.add(lab); l[0]=new Label("Account Number"); l[1]=new Label("Initial Balance"); l[2]=new Label("Deposit Amount"); l[3]=new Label("Withdraw Amount"); for(int i=0;i<4;i++) { t[i]=new TextField(10); p.add(l[i]); p.add(t[i]); } p.add(but); p.add(but1); but1.setVisible(false); l[2].setVisible(false); l[3].setVisible(false); t[2].setVisible(false); t[3].setVisible(false); add(p); add(p1); } String testAccount(int d_amt,int w_amt) { String msg; b.deposit(d_amt); msg="Transaction Succesful"; try { b.withdraw(w_amt); }catch(FundsInsufficientException fe) { fe=new FundsInsufficientException(b.amount,w_amt); msg=String.valueOf(fe); } return msg; } public void actionPerformed(ActionEvent ae) { String str=ae.getActionCommand(); if(str.equals("Create Account")) { b=new BankAccount(Integer.parseInt(t[0].getText()),Integer.parseInt(t[1].getText())); but1.setVisible(true); l[2].setVisible(true); l[3].setVisible(true); t[2].setVisible(true); t[3].setVisible(true); but.setVisible(false); l[0].setVisible(false); l[1].setVisible(false); t[0].setVisible(false); t[1].setVisible(false); lab1.setText("Account : "+b.accnum+", Current Balance : "+b.amount); return; } else { lab.setText(testAccount(Integer.parseInt(t[2].getText()),Integer.parseInt(t[3].getText()))); lab1.setText("Account : "+b.accnum+", Current Balance : "+b.amount); } } public static void main(String arg[]) { GuiAccTest at=new GuiAccTest(); at.setTitle("Bank Account Tester"); at.setSize(600,200); at.setVisible(true); } } class NewWindowAdapter extends WindowAdapter { public void windowClosing(WindowEvent we) { System.exit(0); } } class BankAccount { int accnum; int amount; BankAccount(int num,int amt) { accnum=num; amount=amt; } public void deposit(int amt) { amount=amount+amt; } public void withdraw(int amt) throws FundsInsufficientException { if(amt>amount) throw new FundsInsufficientException(amount,amt); else amount=amount-amt; } } class FundsInsufficientException extends Exception { int balance; int withdraw_amount; FundsInsufficientException(int bal,int w_amt) { balance=bal; withdraw_amount=w_amt; } public String toString() { return "Your withdraw amount ("+withdraw_amount+") is less than the balance ("+balance+"). No withdrawal was recorded."; } }
File Accounts.java
package com.company;
class Accounts{
private int Account_number;
private int balance;
private String type;
private int intrest;
Accounts(){
Account_number=0;
balance =0;
type = null;
intrest=0;
}
Accounts(int Account_number,int balance,String type,int intrest){
setAccount_number(Account_number);
setbalance(balance);
settype(type);
setintrest(intrest);
}
// set getters and setters
public void setintrest(int intrest){
this.intrest=intrest;
balance += this.intrest;
}
public void settype(String type) {
this.type = type;
}
public void setbalance(int balance){
this.balance=balance;
}
public void setAccount_number(int Account_number){
this.Account_number=Account_number;
}
public int getAccount_number(){
return Account_number;
}
public int getbalance(){
return balance;
}
public String gettype(){
return type;
}
public int getintrest(){
return intrest;
}
public void deposit(int amount)
{
balance += amount;
System.out.println("Amount deposited successfully.");
System.out.println("Final Account balance after deposit is: "+getbalance());
}
public void withdraw(int amount)
{
if(getbalance() >= amount)
{
balance -= amount;
System.out.println("Amount withdrawn successfully.");
System.out.println("Final Account balance after withdraw is: "+getbalance());
}
else
{
System.out.println(">>>Insufficient funds in the account to process the withdraw<<<");
}
}
@Override
public String toString() {
return " [Account_number=" + Account_number + ", balance=" + balance + ", type=" + type + ", intrest="
+ intrest + "]";
}
}
File Main.java
package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Accounts account = new Accounts();
Scanner input = new Scanner(System.in);
System.out.print("Enter account number: ");
account.setAccount_number(Integer.parseInt(input.nextLine()));
System.out.print("Enter initial balance: ");
account.setbalance(Integer.parseInt(input.nextLine()));
System.out.print("Enter account type: ");
account.settype(input.nextLine());
String choice = "";
while(true)
{
int amount;
System.out.println("****** MENU ******");
System.out.println("(D)eposit");
System.out.println("(W)ithdraw ");
System.out.println("(A)dd Interest");
System.out.println("(Q)uit");
System.out.print("Enter your choice: ");
choice = input.nextLine();
if(choice.equalsIgnoreCase("D"))
{
System.out.print("Enter amount to deposit: ");
amount = Integer.parseInt(input.nextLine());
if(amount < 0)
{
System.out.println("Invalid amount to deposit! ");
continue;
}
account.deposit(amount);
continue;
}
if(choice.equalsIgnoreCase("W"))
{
System.out.print("Enter amount to withdraw: ");
amount = Integer.parseInt(input.nextLine());
if(amount < 0)
{
System.out.println("Invalid amount to withdraw! ");
continue;
}
account.withdraw(amount);
continue;
}
if(choice.equalsIgnoreCase("A"))
{
System.out.print("Enter interest amount to add: ");
amount = Integer.parseInt(input.nextLine());
account.setintrest(amount);
continue;
}
if(choice.equalsIgnoreCase("Q"))
{
break;
}
System.out.println("Invalid Input!");
System.out.println("Please try again");
continue;
}
System.out.println("Account information.");
System.out.println(account);
System.out.println(" Have a nice day!");
System.out.println("GoodBye.");
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started