-
November 29th, 2015, 09:40 AM
#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.
-
November 29th, 2015, 10:25 AM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|