here is everything I have so far I don't know how to implement these two classes with the array of 10 and get them into the gui fields properly. If anyone can help I would appreciate it I tried asking my teacher for help and he really didn't give me a straight answer he talked me in circles.
class BankAccount
{
int accnum;
static int amount;
private static double withdraw;
CPerson person;
public int getAccnum() {
return accnum;
}
public void setAccnum(int accnum) {
this.accnum = accnum;
}
public static int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
BankAccount(int num,int amt,String nam,int ag)
{
accnum=num;
amount=amt;
person = new CPerson("",0);
}
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;
}
public static double getWithdraw() {
return withdraw;
}
public static void setWithdraw(double withdraw) {
BankAccount.withdraw = withdraw;
}
}
[code=java]import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class BankGui {
JTextField text[];
JButton deposit,withdraw,exit,clear;
JLabel label[];
BankGui(){
text = new JTextField[4];
label = new JLabel[4];
for(int i=0;i<4;i++){
label[0]= new JLabel("Deposit");
text[0]= new JTextField("0");
label[1]= new JLabel("Withdraw");
text[1]= new JTextField("0");
label[2]= new JLabel("Name");
text[2]= new JTextField("Chris");
label[3]= new JLabel("Balance");
text[3]= new JTextField("0");
}
deposit = new JButton("Deposit");
withdraw = new JButton("Withdraw");
exit = new JButton("Exit");
clear = new JButton("Clear");
JPanel jp = new JPanel();//center
JPanel jb = new JPanel();//south
JPanel jd = new JPanel();//west
JFrame jc= new JFrame("bank");
jp.setLayout(new GridLayout(4,2));
for(int i=0;i<3;i++){
jp.add(label[0]);
jp.add(text[0]);
jp.add(label[1]);
jp.add(text[1]);
jp.add(label[2]);
jp.add(text[2]);
jp.add(label[3]);
jp.add(text[3]);
}
jb.setLayout(new GridLayout(3,1));
jb.add(deposit);
jb.add(withdraw);
jb.add(exit);
jb.add(clear);
jc.setLayout(new BorderLayout());
jc.add(jp, BorderLayout.CENTER);
jc.add(jb,BorderLayout.SOUTH);
jc.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jc.setSize(300,500);
jc.setVisible(true);
exit.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){
System.exit(0);};
;});
clear.addActionListener(new ActionListener() {
public void actionPerformed( ActionEvent e) {
for(int i=0;i<4;i++){
text[0].setText("0");
text[1].setText("0");
text[2].setText("Enter name");
text[3].setText("0");
}
}
});
withdraw.addActionListener(new ActionListener() {
public void actionPerformed( ActionEvent e) {
double wd = Double.parseDouble(text[1].getText());
double wdamount = BankAccount.getWithdraw() - wd;
//BankAccount.withdraw(wdamount);
wd = wdamount;
text[3].setText("Balance: " + wd);
}
});
}
public static void main(String[] args) {
BankGui inc = new BankGui();
BankAccount users[] = new BankAccount[10];
users[0]= new BankAccount(56,1000,"Jack",47);
}
}
public class CPerson {
private static String name;
private static int age;
public static String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public static int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public CPerson(String name, int age) {
super();
this.name = name;
this.age = age;
}
CPerson aperson[] = new CPerson[10];
}
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.";
}
}