杰帕内尔
我有上面的jpanel,我正在与之合作。当用户单击“添加贷款”按钮时,我希望他们能够在jlist中显示贷款(对象)数组(“贷款”下的白色块)。
actionlistener如下所示:
addLoan.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Loan loan =
Calculator.createLoan(
Double.parseDouble(loanAmount.getText()),
Double.parseDouble(interestRate.getText()),
Double.parseDouble(term.getText()));
Calculator.addALoan(loan);
}
});
单击此按钮时,我希望显示此方法:
public static void printAllLoans() {
for(int i = 0; i < loans.size(); i++) {
System.out.println("Amount: " + loans.get(i).getAmount());
System.out.println("InterestRate: " + loans.get(i).getInterestRate());
System.out.println("Term: " + loans.get(i).getTerm());
}
}
calculator.addaloan的方法如下:
public static void addALoan(Loan loan) {
loans.add(loan);
}
这会将贷款对象添加到对象的arraylist中:
Ex: Loan(loanAmount, interestRate, term)
public static ArrayList<Loan> loans = new ArrayList<Loan>();
我试过这个:
DefaultComboBoxModel model = new DefaultComboBoxModel(Calculator.loans.toArray());
showLoans.setModel(model);
当然,这不会返回我想要的结果,因为我正在尝试打印对象的arraylist。
我想也许cell render可以做到,但不太确定如何做到。
暂无答案!
目前还没有任何答案,快来回答吧!