Hi need help and explanation to fix the following error in my java program. I can not get the program to show a gui pop-up window. I have to turn this end by 12midnight EST.
Just looked at this code, when you see that dos window and no GUI it is because you have no main () method.
A JAVA program needs a main () method to run the error I see indicates you have none. ( )
here is my complete code;
/*
*
*
* Author P. Manus
* Week 3: Computer Programming I POS/407
* Programmer: Paul Manus
* Date: July 22, 2007
* Filename: MortCalcuWk3.java
* Purpose: Complete Change Request #5 in Service Request SR-mf-
* 003. Insert comments in the program to document the program.
* Attach a design flow chart to the source code of the program.
* This project accepts three user inputs
* using GUI principle,term, and interest then calculates and
* return the monthly payment for the mortgage loan.
*
*/
//Import java packages
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.lang.*;
import java.text.NumberFormat;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
public class MortCalcuWk3 extends JFrame implements ActionListener
{
// Labels
JLabel AmountLabel = new JLabel( "Mortgage Amount:$ " );
JLabel PaymentLabel = new JLabel( "Monthly Payment: " );
JLabel InterestLabel = new JLabel( "Interest Rate %: " );
JLabel TermofLoanLabel = new JLabel( "TermofLoan of Loan: " );
// Text Fields
JTextField mortgageAmount = new JTextField(7);
JTextField MonthlyPayment = new JTextField(7);
JTextField InterestRate = new JTextField(7);
JTextField TermofLoan = new JTextField(7);
// Buttons
JButton Loan1 = new JButton( "7 years at 5.35%" );
JButton Loan2 = new JButton( "15 years at 5.50%" );
JButton Loan3 = new JButton( "30 years at 5.75%" );
JButton ExitButton = new JButton( "Exit" );
JButton ClearButton = new JButton( "Clear" );
JButton CalculateButton = new JButton( "Calculate" );
JButton SaveButton = new JButton( "Save" );
JButton ChartButton = new JButton( "Show Chart" );
// Text Area and Scroll
JTextArea MortgageTable = new JTextArea(25,40);
JScrollPane scroll = new JScrollPane(MortgageTable);
//MortCalcWk3()Method
{
//Frame, Panel, and Layout set up
setSize(600, 400);
setLocation(0, 0);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pane = new JPanel();
pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
//Setup container and contents
Container grid = getContentPane();
grid.setLayout(new GridLayout(4,0,5,5));
pane.add(grid);
pane.add(scroll);
grid.add(AmountLabel);
grid.add(mortgageAmount);
grid.add(InterestLabel);
grid.add(InterestRate);
grid.add(TermofLoanLabel);
grid.add(TermofLoan);
grid.add(PaymentLabel);
grid.add(MonthlyPayment);
grid.add(Loan1);
grid.add(Loan2);
grid.add(Loan3);
grid.add(SaveButton);
grid.add(CalculateButton);
grid.add(ClearButton);
grid.add(ExitButton);
grid.add(ChartButton);
MonthlyPayment.setEditable(false);
setContentPane(pane);
setVisible(true);
//Adds Action Listeners
ExitButton.addActionListener(this);
ClearButton.addActionListener(this);
Loan1.addActionListener(this);
Loan2.addActionListener(this);
Loan3.addActionListener(this);
mortgageAmount.addActionListener(this);
InterestRate.addActionListener(this);
TermofLoan.addActionListener(this);
MonthlyPayment.addActionListener(this);
CalculateButton.addActionListener(this);
} //End MortCalcuWk3 method
public void actionPerformed(ActionEvent e)
{
Object command = e.getSource();
if
(
command == ExitButton)
System.exit(0);
int loanTermofLoan = 0;
if (command == Loan1)
{
loanTermofLoan = 0; //Sets 1st value of Array
TermofLoan.setText("0");
InterestRate.setText("0");
}
if (command == Loan2) //Activates the 2nd Loan Button
{
loanTermofLoan = 1; //Sets 2nd value of Array
TermofLoan.setText("0");
InterestRate.setText("0");
}
if (command == Loan3) //Activates the 3rd Loan Button
{
loanTermofLoan = 2; // Sets 3rd value of Array
TermofLoan.setText("0");
InterestRate.setText("0");
}
if (command == CalculateButton ) //Activates the Calculate Button for manual entries
{
loanTermofLoan = 3; // Sets 4rd value of Array
}
double t1 = Double.parseDouble(TermofLoan.getText());
double r1 = Double.parseDouble(InterestRate.getText());
double [][] loans = { {7, 5.35}, {15, 5.50}, {30, 5.75}, {t1, r1} };
double mortgage = 0; // Declares and Initializes mortgage
mortgage = Double.parseDouble(mortgageAmount.getText());
double interestRate = loans [loanTermofLoan][1];
double intRate = (interestRate / 100) / 12;
double loanTermofLoanMonths = loans [loanTermofLoan] [0];
int months = (int)loanTermofLoanMonths * 12;
double interestRateMonthly = (intRate / 12);
double payment = mortgage * intRate / (1 - (Math.pow(1/(1 + intRate), months)));
double remainingLoanBalance = mortgage;
double MonthlyPaymentInterest = 0;
double MonthlyPaymentPrincipal = 0;
// Number formatter to format output in table
NumberFormat CurrencyFormatter = NumberFormat.getCurrencyInstance (Locale.US);
MonthlyPayment.setText(CurrencyFormatter.format(payment));
MortgageTable.setText("Month\tPrincipal\tInterest\tEnding Balance\n" + // Formats TextArea Header
"----------\t------------\t-------------\t----------------------\n"); // Formats TextArea Header cont.
for (;months > 0 ; months -- )
{
//Append loop for mortgage detail in the text area
MonthlyPaymentInterest = (remainingLoanBalance * intRate);//Monthly Payment Toward Interest
MonthlyPaymentPrincipal = (payment - MonthlyPaymentInterest);//Monthly Payment Toward Principal
remainingLoanBalance = (remainingLoanBalance - MonthlyPaymentPrincipal);//Remaining loan Balance
MortgageTable.setCaret (new DefaultCaret()); // Sets Scroll position to the top left corner
MortgageTable.append(String.valueOf(months) + "\t" +
CurrencyFormatter.format(MonthlyPaymentPrincipal) + "\t" +
CurrencyFormatter.format(MonthlyPaymentInterest) + "\t" +
CurrencyFormatter.format(remainingLoanBalance) + "\n");//
}
//New calculation button
if(command == ClearButton)
{
mortgageAmount.setText(null);
MonthlyPayment.setText(null);
InterestRate.setText(null);
TermofLoan.setText(null);
MortgageTable.setText(null);
};
public static void main (String[] args);
} }
Paul