我試圖創建一個程序,它將從JTextField獲取用戶輸入,並在單擊JButton後將該輸入添加到類CurrentAccount的對象中。到目前爲止,我能夠提出這個代碼;通過GUI向用戶輸入參數添加用戶輸入java
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);
}
});
但我在行中收到錯誤theAccount = new CurrentAccount(balance)。此外,我已經在方法外部實例化了Account,因爲我將需要它作爲類SavingsAccount的對象,因爲它是從中繼承的抽象類Account。
如果有幫助,我的CurrentAccount的代碼如下;
public class CurrentAccount extends Account
{
private int myBalance;
private final ControlPanel myPane;
private int balance;
public CurrentAccount(ControlPanel myPane)
{
// balance= myBalance;
myBalance = myPane.getDimension();
this.myPane=myPane;
// //super(balance);
//if (100 >= myPane) throw new IllegalArgumentException
//("A Savings Account can not have a balance of less than £100, you entered" + balance);
}
任何幫助,這將非常感激。
「我收到錯誤」什麼錯誤? – resueman
對不起,應該提到。在我提到的我即將收到的錯誤「incompatable類型:int不能轉換爲ControlPanel」錯誤 – brushbrushbrush
對此問題已經有一個開放的問題,你忽略了一個問題,其評論。請不要重新提出問題,請不要忽視評論。此問題已被關閉。 –