我尝试使用下面的API来调用while循环动画:在循环错误调用方法
public void animate(String currentTransaction, double currentAmount, double currentBalance)
我想以此来拨打电话:
animate( currentTransaction, currentAmount, currentBalance);
但是,我不断收到错误。我究竟做错了什么?
的错误是:
currentTransaction cannot be resolved to a variable and
currentBalance cannot be resolved to a variable
下面发布是我的代码:
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
import javax.swing.JFrame;
import java.awt.Graphics;
import java.util.StringTokenizer;
import java.util.Scanner;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.FileNotFoundException;
public class Accounting extends JFrame {
private BankAccount bankAccount;
public Accounting() {
bankAccount = new BankAccount(getBackground());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300, 300);
setVisible(true);
}
public void balanceCheckBook() {
double balance;
double currentAmount;
String nextLine;
StringTokenizer st;
String transactionName;
Scanner scan = null;
try {
scan = new Scanner (new FileReader("transactions.txt"));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Scanner callParse;
String trans;
while (scan.hasNextLine()) {
trans = scan.nextLine();
scan.useDelimiter(":");
callParse = new Scanner(trans);
callParse.useDelimiter(":");
}
try {
scan = new Scanner (new FileReader("checkbook.txt"));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Scanner callParse2;
String check;
while (scan.hasNextLine()) {
check = scan.nextLine();
scan.useDelimiter(":");
callParse2 = new Scanner(check);
callParse2.useDelimiter(":");
}
animate( currentTransaction, currentAmount, currentBalance);
}
public void animate(String currentTransaction, double currentAmount, double currentBalance) {
// set the current transaction in the bankAccount object
if (currentTransaction.startsWith("Ch"))
bankAccount.setCurrentTransaction(new Check(currentAmount));
else if (currentTransaction.startsWith("With"))
bankAccount.setCurrentTransaction(new Withdrawal(currentAmount));
else if (currentTransaction.startsWith("Dep"))
bankAccount.setCurrentTransaction(new Deposit(currentAmount));
else
bankAccount.setCurrentTransaction(new UnknownTransaction(currentAmount));
// set the currentBalance data member in the bankAccount object
bankAccount.updateBalance(currentBalance);
repaint();
try {
Thread.sleep(3000); // wait for the animation to finish
} catch (Exception e) {
}
}
public void paint(Graphics g) {
super.paint(g);
bankAccount.draw(g);
}
public static void main(String [] args) {
Accounting app = new Accounting();
app.balanceCheckBook();
}
}
什么是错误?你可以发布吗? – Smit
你能发送错误吗? –
'currentTransaction'未定义 – nachokk