CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2015
    Posts
    1

    Adding user input into an objects parameters via a GUI java

    I'm trying to create a program that will take a users input from a JTextField and add that input to an object of the class CurrentAccount after a JButton has been clicked. So far ive been able to come up with this code;

    jButton1.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e)
    {
    //Execute when button is pressed
    String currentValue = jTextField1.getText() ;
    int val = Integer.parseInt(currentValue);
    balance = val;
    theAccount = new CurrentAccount(balance);
    System.out.println(theAccount.myBalance);


    }
    });

    But i am only able to output 0 as the value isn't being stored as a parameter within the object of CurrentAccount. If you need my code for the class Current Account it is as follows.

    public class CurrentAccount extends Account
    {
    private int myBalance;
    // private final ControlPanel myPane;


    private int balance;

    public CurrentAccount(int myBalance)
    {
    balance= myBalance;

    }
    }

    If anyone can help me with this i would be delighted and the help would be much appreciated.

  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Adding user input into an objects parameters via a GUI java

    Norm

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured