所以我创建了一个带有事务的arraylist。我正在尝试将此信息传递给带有表的mt Frame类。这没有发生。请帮助
public class AccountsClass {
private int AccountNumber;
private String AccName;
private double Balance;
private String Date;
public ArrayList Transactions;
public void NewAccount (){
Scanner in = new Scanner(System.in);
System.out.print("New Account Number? ");
this.AccountNumber = in.nextInt();
in.nextLine();
System.out.print("Account Name? ");
this.AccName = in.nextLine();
System.out.print("Initial Balance ? ");
this.Balance = in.nextInt();
in.nextLine();
System.out.print("Open Date? ");
this.Date = in.nextLine();
Transactions = new ArrayList();
Transactions.add(AccountNumber);
Transactions.add(AccName);
Transactions.add(Balance);
Transactions.add(Date);
这是我的Jframe表类:
public class NewJFrame extends javax.swing.JFrame {
/**
* Creates new form NewJFrame
*/
public NewJFrame() {
initComponents();
addtoJ();
System.out.print("jjjjjj ");
}
public ArrayList Record;
public void addtoJ ()
{DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
// Record1 = new Record;
// new Record = AccountsClass.Transactions;
//Record = new ArrayList();
Record = AccountsClass.Transactions;
Object rowData[] = new Object[4];
for(int i = 0; i < Record.size(); i++)
{
rowData[0] = Record.get(i);
rowData[1] = Record.get(i);
rowData[2] = Record.get(i);
rowData[3] = Record.get(i);
model.addRow(rowData);
}
}
我收到有关非静态到静态的错误消息。我正在尝试为银行对帐单创建交易清单
您不能通过Class本身访问非静态变量和方法。您需要创建该类的对象,然后使用它来获取变量。
但是对于您的情况,您希望AccountsClass.Transactions
是静态的。
public static ArrayList Transactions;
public static void NewAccount (){...}
也请在命名类,方法和变量时遵循标准。它将对您将来有所帮助。交易应该是交易。NewAccount方法应该只是该类的构造方法。AccountsClass应该是Accounts。