java-银行系统-将数组列表从主表传递到JFrame表

问题描述 投票:0回答:1

所以我创建了一个带有事务的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);
    }
}

我收到有关非静态到静态的错误消息。我正在尝试为银行对帐单创建交易清单

java netbeans jframe jtable
1个回答
0
投票

您不能通过Class本身访问非静态变量和方法。您需要创建该类的对象,然后使用它来获取变量。

但是对于您的情况,您希望AccountsClass.Transactions是静态的。

public static ArrayList Transactions;

public static void NewAccount (){...}

也请在命名类,方法和变量时遵循标准。它将对您将来有所帮助。交易应该是交易。NewAccount方法应该只是该类的构造方法。AccountsClass应该是Accounts。

© www.soinside.com 2019 - 2024. All rights reserved.