public class Account extends javax.swing.JFrame {

/** Creates new form Account */
public Account() {
setTitle("Bank Account");

* @param args the command line arguments

private int accountNumber =0;
private double balance =0;

public Account(int accNum, double bal)
accountNumber = accNum;
balance = bal;

public void deposit(double amount)

private void buttonCreateActionPerformed(java.awt.event.ActionEvent evt) {

Account newAcc = new Account(1234, 20000.0);
jTextArea1.setText("Account Created \nAccount Number ="+newAcc.ID+", Account Balance= "+newAcc.balance);

private void buttonDepositActionPerformed(java.awt.event.ActionEvent evt) {
/*i am trying to do : newAcc.deposit(5000.0);
jTextArea1.setText("new balance : "+balance);*/

/*but newAcc can't call the method deposit
i want it so that each time buttonDeposit is clicked, 5000 is added to the initial balance, which is 20000;


please help, i'm a newbie to java

Edited by happygeek: fixed formatting

6 Years
Discussion Span
Last Post by JamesCherrill

Account newAcc is defined inside buttonCreateActionPerformed so it can't be accessed from outside that method.
You haven't explained the overall logic of your app, so I can't suggest the best way to fix this. But deposit is an instance method of Account, so you should just be able to call deposit(5000.0); in buttonDepositActionPerformed (which is an instance method, so the instance of Account is already part of its context and doesn't need to specified again).

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.