Hello there,
I'm brand new to Java and have. I'm taking my 2nd Java class at school and I'm pretty lost at this point.
The main problem I'm having right now is I cannot get my code to execute. My code will compile, but when I try to execute it, either just using the "java" command or executing from TextPad, I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: MortgagePayment1
Press any key to continue . . .
In my last class, my compiler was working fine and I could easily execute all of my applications. However, I stupidly ran Windows Updates and it installed Java 6 on my computer and nothing has worked right since.
When I execute "java -version" from a command line, this is what I get:
java version "1.6.0_01"
Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)
Here's the code I've compiled and am trying to execute:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.text.DecimalFormat;
public class MortgagePayment1 extends JFrame implements ActionListener
{
private JTextField mortgageAmount;
private JTextField mortgageTerm;
private JTextField interestRate;
private JTextField mortgagePaymentAmount;
private JButton calculateBtn;
private JButton quitBtn;
public MortgagePayment1() {
JPanel contentPane = (JPanel)getContentPane();
contentPane.setLayout(new BorderLayout(0, 4));
JPanel northPanel = new JPanel();
Border b = BorderFactory.createEtchedBorder();
northPanel.setBorder(BorderFactory.createTitledBor der(b, "Calculate Mortgage Payment", TitledBorder.TOP, TitledBorder.CENTER));
northPanel.setLayout(new GridLayout(4, 2, 10, 10));
JLabel mortgageAmountLabel = new JLabel("Input Initial Mortgage Amount (dollars)", JLabel.RIGHT);
JLabel mortgageTermLabel = new JLabel("Input Mortgage Term (years)", JLabel.RIGHT);
JLabel interestRateLabel = new JLabel("Input Interest Rate", JLabel.RIGHT);
JLabel mortgagePaymentAmountLabel = new JLabel("Mortgage Payment Amount", JLabel.RIGHT);
mortgageAmount = new JTextField(10);
mortgageTerm = new JTextField(10);
interestRate = new JTextField(10);
mortgagePaymentAmount = new JTextField(10);
northPanel.add(mortgageAmount);
northPanel.add(mortgageTerm);
northPanel.add(interestRate);
northPanel.add(mortgagePaymentAmount);
northPanel.add(mortgageAmountLabel);
northPanel.add(mortgageTermLabel);
northPanel.add(interestRateLabel);
northPanel.add(mortgagePaymentAmountLabel);
// add the rest of labels and textfields
JPanel southPanel = new JPanel();
calculateBtn = new JButton("Calculate");
southPanel.add(calculateBtn);
calculateBtn.addActionListener(this);
quitBtn = new JButton("Quit");
southPanel.add(quitBtn);
quitBtn.addActionListener(this);
contentPane.add(northPanel, BorderLayout.NORTH);
contentPane.add(southPanel, BorderLayout.SOUTH);
}
public void actionPerformed(ActionEvent evt)
{
JButton sourceBtn = (JButton)evt.getSource();
if (sourceBtn == calculateBtn)
{
//calculate monthly payment
//.... set mortgagePaymentAmount textfield to monthly payment.
}
else if (sourceBtn == quitBtn)
{
System.exit(0);
}
}//close actionPerformed method
public static void main(String[] args)
{
MortgagePayment1 mp1 = new MortgagePayment1();
mp1.setTitle("Mortgage Payment: Assignment 1 developed by ...");
mp1.pack();
mp1.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
Window w = e.getWindow();
w.setVisible(false);
w.dispose();
System.exit(0);
}//close windowClosing method
});//close addWindowListener method
mp1.setVisible(true);
}//close Main method
}//close MortgagePayment1 class
Any help would be greatly appreciated.