Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-13-2012, 03:24 AM   PM User | #1
cjolejniczak
New to the CF scene

 
Join Date: Dec 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
cjolejniczak is an unknown quantity at this point
Bank Account GUI

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.

[code=java]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.";
}
}
[code]
cjolejniczak is offline   Reply With Quote
Old 12-13-2012, 07:30 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
This is the JavaScript forum. Java and Javascript are entirely different programming languages, in spite of the confusingly similar names. Rather like Austria and Australia! Ask a mod to move this thread to the right forum.

BTW, when posting here please help us to help you by following the posting guidelines and wrapping your code in CODE tags. This means use the octothorpe or # button on the toolbar. You can (and should) edit your previous post.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is online now   Reply With Quote
Old 12-13-2012, 09:08 PM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,189
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
REALLY REALLY bad code, in any case.

Code:
private static double withdraw;
Se even if you have a million people in your system, each with his/her own BankAccount instance, there is only *ONE* common withdraw number.

That makes no sense at all.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote
Reply

Bookmarks

Tags
array, composition, gui

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:02 PM.


Advertisement
Log in to turn off these ads.