我正在为投资组合创建贷款申请计划。但是,我似乎忘记了如何从另一个类调用/调用/创建方法。我确定我没有意义!这是我的代码片段:
public class ButtonListener implements ActionListener{
@Override
public void actionPerformed (ActionEvent e){
String firstName = LoanerFirstName.getText();
String middleI = LoanerMiddleInitial.getText();
String lastName = LoanerLastName.getText();
double interest = Double.parseDouble(AIR.getText());
int Years = Integer.parseInt(NumOfYears.getText());
double loanAmount = Double.parseDouble(LoanAmount.getText());
double monthlyPayment = Double.parseDouble(MonthlyPayment.getText());
double totalPayment = Double.parseDouble(TotalPayment.getText());
Loan loan = new Loan(interest, Years, loanAmount);
MonthlyPayment.setText(String.format("%.2f", loan.getMonthlyPayment()));
TotalPayment.setText(String.format("%.2f", loan.getTotalPayment()));
}
“Loan”类未被识别(以红色加下划线;错误)。
P.S:我正在使用NetBeans 8.0 for Windows 8。
答案 0 :(得分:1)
您必须在使用之前导入课程。
如果您使用:
Loan loan = new Loan(interest, Years, loanAmount);
验证您是否拥有该课程的import
。
如果您在lib中使用类,请验证您的类路径中是否有jar文件,然后您需要为您需要的类导入。
答案 1 :(得分:0)
Dear Friend, You first have to import the class you want to use if it is in different package as concerned to your present class as : import packagename.Loan; where packagename is the name of package containing Loan class If the class Loan is in the same package then, you can access it directly as: Create its object and call its constructor at the same time as ---- Loan loan = new Loan(interest, Years, loanAmount); And now using its object loan , you can access different data members of that class. Hope this would effectively help you. Thanks.