Cannot figure out how to add image to Java app?

tickle monster

New member
import java.awt.*; //to create buttons, etc w/o actions
import java.awt.event.*; //to create an event or action
import javax.swing.*;
import javax.swing.JButton; //to create a button
import javax.swing.JTextField; //to create a text field
import java.text.DecimalFormat; //to import decimal format for money

//Class
public class MortgageText extends JPanel implements ActionListener
{
//Global Variable
protected JComboBox MortCombo;
protected JLabel lblprincipal, lblinterestRate, lblTerm, lblmonthlyPayment;
protected JButton calculate, Clear;
protected JTextField principal, interestRate, Term, monthlyPayment;
protected TextArea MortTextField;

public MortgageText()
{
String[] comboItems={"5.35","5.50","5.75",};

//creates labels and fields
lblprincipal=new JLabel("Total Amount:");
principal = new JTextField("",10);
lblinterestRate=new JLabel("Interest Rate:");
interestRate = new JTextField("",10);
lblTerm=new JLabel("Term Years:");
Term = new JTextField("",10);
lblmonthlyPayment=new JLabel("Monthly Payment:");
monthlyPayment = new JTextField("",10);
MortCombo=new JComboBox(comboItems);
MortTextField=new TextArea(10,120);

/
//create buttons
calculate = new JButton("Calculate"); //button used to calculate mortgage payment
calculate.setActionCommand("GO");

Clear = new JButton("Clear"); //button used to clear data from the fields
Clear.setActionCommand("Clear");


//add action to button
calculate.addActionListener(this);
Clear.addActionListener(this);

add(lblprincipal);
add(principal);
add(lblinterestRate);
add(MortCombo);
add(lblTerm);
add(Term);
add(lblmonthlyPayment);
add(monthlyPayment);
add(calculate);
add(Clear);
add(MortTextField);

}
public void actionPerformed(ActionEvent e)
{
if ("GO".equals(e.getActionCommand()))
{
CalculateMortgage();
}
else
{
principal.setText("");
interestRate.setText("");
Term.setText("");
monthlyPayment.setText("");
}
}

// principal.setText(interestRate.getText()); --this will read the interestRate text field and copy it to the principal field

public void CalculateMortgage()
{
double dblprincipal=Double.parseDouble(principal.getText());
double dblinterestRate=Double.parseDouble((String)MortCombo.getSelectedItem());
int intTerm=Integer.parseInt(Term.getText());
DecimalFormat money = new DecimalFormat("$0.00");


double MonthlyPayment=0.0;
double InterestPayment=0.0;
double PrincipalBal=0.0;
double MIntRate=dblinterestRate/1200;
int MTerms=intTerm * 12;

//monthly payment formula
MonthlyPayment=(dblprincipal * MIntRate) / (1-Math.pow((MIntRate+1),-MTerms));

//converts Monthly Payment to decimal format
monthlyPayment.setText("" + (money.format(MonthlyPayment)));

MortTextField.append("Month No.\t\tMonthly Payment\t\t\tLoan Balance\t\t\tInterest Payment\n");
MortTextField.append("1\t\t\t" + MonthlyPayment + PrincipalBal + InterestPayment + "\n");


for (int counter=1; counter < MTerms; counter++)
{
MortTextField.append((counter + 1) + "\t\t\t" + MonthlyPayment + PrincipalBal + InterestPayment + "\n");
}

}

private static void createAndShowGui()
{
JFrame frame = new JFrame("Calculator");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

MortgageText myCa
I want to add an image to the app thats located on my computer????
 
Back
Top