| | |
Java Error
![]() |
•
•
Join Date: Jul 2007
Posts: 4
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Jul 2007
Posts: 4
Reputation:
Solved Threads: 0
public static void main (String[] args);
I know but not exactly sure how the code should be written. Included the above in my code but get an error msg of illegal start of expression public static void main (String[] args);
I am not java or program material savvy! Help please...
should it be written as public void mortcalcuwk3 (String[] args); or how shoudl it be written to get the gui windows to appear??
I know but not exactly sure how the code should be written. Included the above in my code but get an error msg of illegal start of expression public static void main (String[] args);
I am not java or program material savvy! Help please...
should it be written as public void mortcalcuwk3 (String[] args); or how shoudl it be written to get the gui windows to appear??
The main method is the most basic piece of any program. If you do not understand how to write it then I really have to wonder how you managed to write all of that GUI code yourself.
Anyway, that said, you have the signature for main correct but you have a semicolon at the end and no open brace. It should be:
Anyway, that said, you have the signature for main correct but you have a semicolon at the end and no open brace. It should be:
Java Syntax (Toggle Plain Text)
public static void main(String[] args) { // your code to create the object here }
What I would recommend is checking to make sure that all methods that are not called from an object using the
. operator are declared as static. Otherwise the compiler may just, oh, gosh, not run the blasted thing. Some methods didn't have static in there; I couldn't tell whether or not they were called on their own, but you should keep an eye on that. Buena suerte. Beware of the Rancor. I'm not kidding.
If it doesn't compile, try saying "By the power of MegaMan!!!" <this has kinda worked for me, actually...>
Scotland is NOT North Britain, Glasgow does NOT rhyme with "cow", and Robbie Burns is...well, if you don't already know who he was, you're kinda screwed.
If it doesn't compile, try saying "By the power of MegaMan!!!" <this has kinda worked for me, actually...>
Scotland is NOT North Britain, Glasgow does NOT rhyme with "cow", and Robbie Burns is...well, if you don't already know who he was, you're kinda screwed.
•
•
•
•
What I would recommend is checking to make sure that all methods that are not called from an object using the.operator are declared asstatic. Otherwise the compiler may just, oh, gosh, not run the blasted thing. Some methods didn't havestaticin there; I couldn't tell whether or not they were called on their own, but you should keep an eye on that. Buena suerte.
Sorry. There's always the chance that he's working with one of those really janky compilers (like BlueJ) that show one error and say nothing about the 5,000 others also lurking in your code. But hey, I apologize for my public disservice announcement.
Beware of the Rancor. I'm not kidding.
If it doesn't compile, try saying "By the power of MegaMan!!!" <this has kinda worked for me, actually...>
Scotland is NOT North Britain, Glasgow does NOT rhyme with "cow", and Robbie Burns is...well, if you don't already know who he was, you're kinda screwed.
If it doesn't compile, try saying "By the power of MegaMan!!!" <this has kinda worked for me, actually...>
Scotland is NOT North Britain, Glasgow does NOT rhyme with "cow", and Robbie Burns is...well, if you don't already know who he was, you're kinda screwed.
•
•
Join Date: Jul 2007
Posts: 4
Reputation:
Solved Threads: 0
Guys, sorry but just give me exactly how the code should be written, so i cn turn in my assignment by tonight! Like i said i'll never be a java programmer and i am just trying to complete this class.. I have no shame here but there has been an over kill of progrmming classes just to complete a BSIT degree it is almost tlike I am going for a computer sicence degree vs. info tech... thta is the reason i went for the IT vs. CS to avoid too many programming classes.
Sun's tutorial "How to Make Frames"
http://java.sun.com/docs/books/tutorial/uiswing/components/frame.html
http://java.sun.com/docs/books/tutorial/uiswing/components/frame.html
Last edited by Ezzaral; Jul 23rd, 2007 at 4:47 pm.
![]() |
Similar Threads
- Java Causes IE to Crash...Java not working (Web Browsers)
- I need a good java compiler (Java)
- Error message when trying to install Java (Windows 95 / 98 / Me)
- DNS: RouteThrough , " RT" in java networking programming (Java)
- Help Java Error "Java not found" (HTML and CSS)
- programme runing error (Windows NT / 2000 / XP)
- DNS Error (Web Browsers)
- java chat problem (Windows 95 / 98 / Me)
Other Threads in the Java Forum
- Previous Thread: [help_reqd]Noobie needs help
- Next Thread: adding classes at run time (plug-in?)
| Thread Tools | Search this Thread |
account android api applet application array arrays automation bidirectional binary birt bluetooth class classes client code columns component constructor database designadrawingapplicationusingjavajslider draw eclipse error errors exception expand fractal game givemetehcodez graphics gui guidancer homework html ide image inetaddress inheritance integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jlabel jme jni jpanel jtextfield jtree julia linux list loop map method methods midlethttpconnection mobile mobiledevelopmentcreatejar monitoring myaggfun netbeans newbie nullpointerexception open-source oracle plazmic print problem program project property recursion ria scanner search server set sharepoint smart sms smsspam sort sourcelabs splash sql sqlite static string subclass support swing testautomation threads tree unlimited webservices windows






