User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 425,933 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,632 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 1307 | Replies: 11
Reply
Join Date: Jul 2007
Posts: 4
Reputation: manusp is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
manusp manusp is offline Offline
Newbie Poster

Java Error

  #1  
Jul 23rd, 2007
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 2,840
Reputation: Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all 
Rep Power: 12
Solved Threads: 282
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Maven

Re: Java Error

  #2  
Jul 23rd, 2007
Your message already mentions the problem. Your main() method does not do anything. It needs to create the instance of the class and show it.
Reply With Quote  
Join Date: Jul 2007
Posts: 4
Reputation: manusp is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
manusp manusp is offline Offline
Newbie Poster

Re: Java Error

  #3  
Jul 23rd, 2007
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??
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 2,840
Reputation: Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all 
Rep Power: 12
Solved Threads: 282
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Maven

Re: Java Error

  #4  
Jul 23rd, 2007
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:
public static void main(String[] args) {
   // your code to create the object here
}
Reply With Quote  
Join Date: Oct 2006
Location: Evanston IL
Posts: 132
Reputation: venomlash is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
venomlash's Avatar
venomlash venomlash is offline Offline
Junior Poster

Troubleshooting Re: Java Error

  #5  
Jul 23rd, 2007
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.
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 2,840
Reputation: Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all 
Rep Power: 12
Solved Threads: 282
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Maven

Re: Java Error

  #6  
Jul 23rd, 2007
Originally Posted by venomlash View Post
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.

That has no bearing on the issue he is having. When to use static methods instead of normal class methods is a separate design issue.
Reply With Quote  
Join Date: Oct 2006
Location: Evanston IL
Posts: 132
Reputation: venomlash is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
venomlash's Avatar
venomlash venomlash is offline Offline
Junior Poster

Re: Java Error

  #7  
Jul 23rd, 2007
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.
Reply With Quote  
Join Date: Jul 2007
Posts: 4
Reputation: manusp is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
manusp manusp is offline Offline
Newbie Poster

Re: Java Error

  #8  
Jul 23rd, 2007
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.
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 2,840
Reputation: Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all 
Rep Power: 12
Solved Threads: 282
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Maven

Re: Java Error

  #9  
Jul 23rd, 2007
Last edited by Ezzaral : Jul 23rd, 2007 at 3:47 pm.
Reply With Quote  
Join Date: Jul 2007
Posts: 4
Reputation: manusp is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
manusp manusp is offline Offline
Newbie Poster

Re: Java Error

  #10  
Jul 23rd, 2007
ezzaral, thanks......
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 9:15 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC