File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes help... I need a feild to fill in Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

help... I need a feild to fill in

Tami Hart
Greenhorn

Joined: Jun 09, 2004
Posts: 7
I have my program working while I am using the drop down menue, However I want to be able to select the JCheckBox and it will allow me to enter any amounts and it will do the math and fill in the monthly payment and the chart. here is my program:

import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.NumberFormat;
import java.math.*;

public class scroll2t extends JFrame implements ActionListener, ItemListener

{//Beginning of Program

// Fields for Principle
JPanel row1 = new JPanel();
JLabel dollar = new JLabel("How much are you borrowing?");
JTextField money = new JTextField(" ", 15);

// Fields for Term and Rate
JPanel row2 = new JPanel();
JLabel choice = new JLabel("Select Year & Rate:");
JCheckBox altchoice = new JCheckBox("Alt. Method");
JTextField YR = new JTextField(" ", 4);
JTextField RT = new JTextField(" ", 4);

//Jcombobox R=rate,Y=year
String[] RY =
{"7 years at 5.35%", "15 years at 5.5 %", "30 years at 5.75%", " "};
JComboBox mortgage = new JComboBox(RY);

// Fields for Payment
JPanel row3 = new JPanel();
JLabel payment = new JLabel("Your monthly payment will be:");
JTextField owe = new JTextField(" ", 15);

//Scroll Pane and Text Area
JPanel row4 = new JPanel();
JLabel amortization = new JLabel("Amortization:");
JTextArea chart = new JTextArea(" ", 7, 22);
JScrollPane scroll = new JScrollPane(chart,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
StringBuffer amt = new StringBuffer();
Container pane = getContentPane();
FlowLayout flow = new FlowLayout(FlowLayout.LEFT);
JButton Cal = new JButton("Calculate");
public scroll2t()
{ //Start of JFrame

// Title and Exit of JFrame
super("Q's Mortgage and Amortization Calculator");
setSize(475, 328);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//JFrame layout


pane.setLayout(flow);

//Input output fields added to JFrame
row1.add(dollar);
row1.add(money);
pane.add(row1);
mortgage.setSelectedIndex(3);
mortgage.addActionListener(this);
row2.add(altchoice);
altchoice.addItemListener(this);
row2.add(choice);
YR.setEditable(false);
RT.setEditable(false);
row2.add(YR);
row2.add(RT);
row2.add(mortgage);
pane.add(row2);
row3.add(payment);
row3.add(owe);
pane.add(row3);
owe.setEditable(false);

//Scroll Pane added to JFrame
row4.add(amortization);
chart.setEditable(false);
row4.add(scroll);
pane.add(row4);

//Executable Button- Clear,Exit, Calculate
JPanel row5 = new JPanel();
JButton clear = new JButton("Clear");
clear.addActionListener(this);
row5.add(clear);
pane.add(row5);

JButton exit = new JButton("Exit");
exit.addActionListener(this);
row5.add(exit);

Cal.setEnabled(false);
row5.add(Cal);
pane.add(row5);

//Column Titles for Text Area

amt.append("Pmt#\tPrincipal\tInterest\tBalance\n");
chart.setText(amt.toString());
setContentPane(pane);
setVisible(true);
} //End of JFrame
public void itemStateChanged(ItemEvent ie)
{
int status = ie.getStateChange();
if (status == ItemEvent.SELECTED)
{
mortgage.setEnabled(false);
YR.setEditable(true);
RT.setEditable(true);
Cal.setEnabled(true);
}
else
{
mortgage.setEnabled(true);
YR.setEditable(false);
RT.setEditable(false);
Cal.setEnabled(false);

}
}
public void actionPerformed(ActionEvent ae)//Calculations and Button executions
{ //Start actionPerformed

String command = ae.getActionCommand();
// Exit program
if (command == "Exit")System.exit(0);

//Define variables loan1 //Define loan2
double Principal = 0; int Year2 = 15;
int Year = 7; double Rate2 = 0.055;
double Rate = 0.0535; int Year3 = 30;
double Interest = 0; double Rate3 = 0.0575;
double Monthly = 0;
NumberFormat currency =
NumberFormat.getCurrencyInstance();

// Cal button
if (command== "Calculate")
{
int y = Integer.parseInt(YR.getText());
double r = Double.parseDouble(RT.getText())/1200;
double P = Double.parseDouble(money.getText());
double In = r / 100 / 12.0;
double M = P * (In / (1 - Math.pow(In + 1, -12.0 * y)));
owe.setText(currency.format(Double.toString(M)));
for (int i=0; i<y*12; i++)
{
double interestAccrued=Principal*Interest;
double principalPaid=Monthly-interestAccrued;
amt.append(i+1 + "\t" +currency.format(principalPaid)
+ "\t" + currency.format(interestAccrued)
+ "\t" + currency.format(Principal) + "\n");
chart.setText(amt.toString());
Principal=Principal+interestAccrued-Monthly;
}

}
// Clear fields
if (command == "Clear")
{
Principal = 0.0F;
money.setText(null);
mortgage.setSelectedIndex(3);
owe.setText(null);
chart.setText(null);
}
// check box

//Execute Combo Array 0
if(mortgage.getSelectedIndex()==0)
{
//mortgage.setSelectedIndex(0);
mortgage.getSelectedItem().toString();
Principal = Double.parseDouble(money.getText());
Interest = Rate / 12.0;
Monthly = Principal * (Interest / (1 - Math.pow(Interest + 1, -12.0 * Year)));
owe.setText(currency.format(Monthly));
for (int i=0; i<Year*12; i++)
{
double interestAccrued=Principal*Interest;
double principalPaid=Monthly-interestAccrued;
amt.append(i+1 + "\t" +currency.format(principalPaid)
+ "\t" + currency.format(interestAccrued)
+ "\t" + currency.format(Principal) + "\n");
chart.setText(amt.toString());
Principal=Principal+interestAccrued-Monthly;
}

}
//Execute Combo Array 1
if(mortgage.getSelectedIndex()==1)
{
//mortgage.setSelectedIndex(1);
mortgage.getSelectedItem().toString();
Principal = Double.parseDouble(money.getText());
Interest = Rate2 / 12.0;
Monthly = Principal * (Interest / (1 - Math.pow(Interest + 1, -12.0 * Year2)));
owe.setText(currency.format(Monthly));
for (int i=0; i<Year2*12; i++)
{
double interestAccrued=Principal*Interest;
double principalPaid=Monthly-interestAccrued;
amt.append(i+1 + "\t" +currency.format(principalPaid)
+ "\t" + currency.format(interestAccrued)
+ "\t" + currency.format(Principal) + "\n");
chart.setText(amt.toString());
Principal=Principal+interestAccrued-Monthly;
}
}
//Execute Combo Array 2
if(mortgage.getSelectedIndex()==2)
{
//mortgage.setSelectedIndex(2);
mortgage.getSelectedItem().toString();
Principal = Double.parseDouble(money.getText());
Interest = Rate3 / 12.0;
Monthly = Principal * (Interest / (1 - Math.pow(Interest + 1, -12.0 * Year3)));
owe.setText(currency.format(Monthly));
for (int i=0; i<Year3*12; i++)
{
double interestAccrued=Principal*Interest;
double principalPaid=Monthly-interestAccrued;
amt.append(i+1 + "\t" +currency.format(principalPaid)
+ "\t" + currency.format(interestAccrued)
+ "\t" + currency.format(Principal) + "\n");
chart.setText(amt.toString());
Principal=Principal+interestAccrued-Monthly;
}
}

} //End actionPerformed

public static void main(String args[])throws IOException
{
scroll2 Calc = new scroll2();
}
}
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Round these parts, posting the same question in multiple forums is bad practice. It can make it rather difficult to follow a conversation, plus folks spend time saying things that were just said.

Please continue in the duplicate post in the Swing / JFC / AWT forum.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help... I need a feild to fill in