Home > Archive > Java Help > March 2004 > Multiple Frame Help
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Multiple Frame Help
|
|
|
| I have two Frame classes so far - BankMainFrame is the parent frame and
contains the main method and BankWithdrawFrame is used as a window that
calls a takes in a monetary value and withdraws this from a Bank object.
BankWithdrawFrame is opened when a "Withdraw" Button is clicked in
BankMainFrame. When it is opened it displays effectively a prompt that asks
for the amount to be withdrawn and has an Ok Button to fire the event that
performs the withdrawal. How do I get the _bank.withdraw(int account_number,
double amount) method to run (_bank is in the parent BankMainFrame class)
and update the details in the parent frame after the withdraw method is
called in BankWithdrawFrame?
It currently isn't working as there is no link between the amount entered
into the BankWithdrawFrame TextField and the _bank object withdraw method
and I don't know how to achieve this.
TIA
#################
import java.awt.*;
import java.awt.event.*;
public class BankMainFrame extends Frame
{
private Bank _bank;
//protected Panel _account_list_panel;
public BankMainFrame()
{
setSize(300,200);
setResizable(true);
setTitle("Bank Frame");
setLocation(150,250);
_bank = new Bank(20);
_bank.openAccount(123, 'K');
_bank.openAccount(456, 'S');
_bank.openAccount(789, 'G');
displayAccountList();
this.pack();
}
private void displayMenu()
{
//
}
private void displayAccountList()
{
Panel _account_list_panel = new Panel(new GridLayout(0,1));
Panel _acc_header = new Panel();
_acc_header.setLayout(new GridLayout(1,4));
_acc_header.add(new Label("Account"));
_acc_header.add(new Label("Balance"));
_acc_header.add(new Label(""));
_acc_header.add(new Label(""));
_account_list_panel.add(_acc_header);
for (int i = 0; i < _bank.getAccountCount(); i++)
{
BasicAccount acc;
Panel acc_row = new Panel();
Button deposit = new Button("Deposit");
Button withdraw = new Button("Withdraw");
acc_row.setLayout(new GridLayout(1,4));
acc = _bank.getAccount(i);
final int acc_number = acc.getAccNumber();
double bal = acc.getBalance();
ActionListener act_deposit = new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
clickDeposit(acc_number);
}
};
ActionListener act_withdraw = new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
clickWithdraw(acc_number);
}
};
deposit.addActionListener(act_deposit);
withdraw.addActionListener(act_withdraw);
acc_row.add(new Label("" + acc_number));
acc_row.add(new Label("" + bal));
acc_row.add(deposit);
acc_row.add(withdraw);
_account_list_panel.add(acc_row);
}
this.add("South", _account_list_panel);
}
private void clickDeposit(int account_number)
{
//Deposit button is clicked
}
private void clickWithdraw(int account_number)
{
BankWithdrawFrame withdraw_frame = new BankWithdrawFrame(_bank,
account_number);
withdraw_frame.show();
}
public static void main(String[] args)
{
BankMainFrame bankframe = new BankMainFrame();
bankframe.show();
}
}
################
import java.awt.*;
import java.awt.event.*;
public class BankWithdrawFrame extends Frame implements ActionListener
{
private int _account_number;
private int _withdraw_amount;
private Bank _bank;
protected Panel _withdraw_panel, _button_panel;
protected TextField _withdraw_amount_tf;
protected Label _withdraw_label;
protected Button _ok_button;
protected Button _cancel_button;
public BankWithdrawFrame(Bank bank, int account_number)
{
_account_number = account_number;
_bank = bank;
setSize(100,200);
setResizable(true);
setTitle("Withdraw");
setLocation(170,270);
_withdraw_panel = new Panel(new FlowLayout());
_button_panel = new Panel(new FlowLayout());
_withdraw_label = new Label("Withdraw Amount" + _account_number);
_withdraw_amount_tf = new TextField(10);
_ok_button = new Button("Ok");
_cancel_button = new Button("Cancel");
_ok_button.addActionListener(this);
_cancel_button.addActionListener(this);
_withdraw_panel.add(_withdraw_label);
_withdraw_panel.add(_withdraw_amount_tf);
_button_panel.add(_ok_button);
_button_panel.add(_cancel_button);
this.add("North", _withdraw_panel);
this.add("South", _button_panel);
this.pack();
}
public void actionPerformed(ActionEvent e)
{
Button clicked_button = (Button)e.getSource();
if (clicked_button == _ok_button)
{
_withdraw_amount = Integer.parseInt(_withdraw_amount_tf.getText());
_bank.withdraw(_account_number, _withdraw_amount);
this.hide();
}
else
{
this.hide();
}
}
}
| |
| Andrew Thompson 2004-03-27, 12:30 am |
| On Wed, 24 Mar 2004 23:11:53 -0000, Si wrote:
> I have two Frame classes so far - BankMainFrame is the parent frame and
> contains the main method and BankWithdrawFrame is used as a window that
> calls a takes in a monetary value and withdraws this from a Bank object.
When I saw your 197 lines of message
I (stupidly) assumed you had included
an SSCCE*, but the code you gave us does
not compile!
* <http://www.physci.org/codes/sscce.jsp>
> BankWithdrawFrame is opened when a "Withdraw" Button is clicked in
> BankMainFrame. When it is opened it displays effectively a prompt that asks
> for the amount to be withdrawn and has an Ok Button to fire the event that
> performs the withdrawal. How do I get the _bank.withdraw(int account_number,
So, you want to get a value back from a
pop-up? Here is an example..
<http://www.physci.org/launcher.jsp#SampleDialog>
And, could I ask you to have a close look
over the first link I gave you? It gives
hints on the best way to produce code when
you need others to help you..
The second thing is that you should not be
cross-posting to three groups, please stick
to c.l.j.help for the moment.
<http://www.physci.org/codes/javafaq.jsp#xpost>
--
Andrew Thompson
* http://www.PhySci.org/ Open-source software suite
* http://www.PhySci.org/codes/ Web & IT Help
* http://www.1point1C.org/ Science & Technology
|
|
|
|
|