0 Replies - 556 Views - Last Post: 30 August 2008 - 07:51 PM Rate Topic: -----

#1 emblem  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 16-April 08

Need some feedback on what to use for this program. Null layout/action

Posted 30 August 2008 - 07:51 PM

I have to write an amortization table and my plan is to make one like this:
http://www.bretwhiss...n/amortize.html

I'm wanting to see if what I want to do is even a good way to go about this assignment.


I've made the general layout of it already. It's just that now I'm trying to get the numbers into the program. I made a separate class that has methods for the formula's and all that but I seem to be having some problem with the .setText and .getText methods in my action listener. They seem to only take strings while I need doubles or something like that.



When calling the method from the class
prog NumMonthlyPayments(.....)

I saw that I can't use .getText in that spot so I decided to just do this
public static class btnCalculateAction implements ActionListener{
		public void actionPerformed (ActionEvent e){
			
		Program101 prog = new Program101();	
			
		String P = txtPrincipal.getText();
		String I = txtAnnualInterestRate.getText();
		String MonthlyPay = txtMonthlyPayment.getText();
		double Pd = Double.parseDouble(P);
		double Id = Double.parseDouble(I);
		double MPd = Double.parseDouble(MonthlyPay);

		prog NumMonthlyPay(Pd,Id,MPd);//I get errors in this
		System.out.println (Pd +Id+MPd);
		
		
		
	   txtNumMonthlyPay.setText("");
	   txtTotalInterestPaid.setText("");
	  
		}
	}


I initialized strings to receive the info from the txt.... variables.(since I apparently can't use double)

Then I make them doubles and call a method from a different class I've made. I get a lot of errors in that line saying "not a statement" and ";" expected.

Is there an easier way of doing this project? Will it prove to be to difficult and should I just go a more basic way of doing it?


public class Program1 {

   //Sets the controls needed.
	static JFrame frame1;
	static Container pane;
	static JLabel lblPrincipal, lblAnnualInterestRate, lblMonthlyPayment,lblNumMonthlyPay, lblTotalInterestPaid;
	static JButton btnCalculate;
	static JTextField txtPrincipal, txtAnnualInterestRate, txtMonthlyPayment,txtNumMonthlyPay, txtTotalInterestPaid;
	static Insets insets;
	
	public static void createControls ()
	{
	//Create controls
		btnCalculate = new JButton ("Calculate");
		lblPrincipal = new JLabel ("Principal");
		lblAnnualInterestRate = new JLabel ("Annual Interest Rate");
		lblMonthlyPayment = new JLabel ("Monthly Payment");
		lblNumMonthlyPay = new JLabel ("Number of Monthly Payments");
		lblTotalInterestPaid = new JLabel ("Total Interest Paid");
		txtPrincipal = new JTextField (10);
		txtAnnualInterestRate = new JTextField ( 10);
		txtMonthlyPayment =  new JTextField (10);
		txtNumMonthlyPay =  new JTextField(10); //I want there to be an output here.
		txtTotalInterestPaid = new JTextField(10);//I want there to be an output here.
		
	}
		
		public static void main(String args[])
	{
		Scanner input = new Scanner(System.in);
		 Program1 loan = new Program1();
		 
		 
	
		//Set Look and Feel
		try {UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());}
		catch (ClassNotFoundException e) {}
		catch (InstantiationException e) {}
		catch (IllegalAccessException e) {}
		catch (UnsupportedLookAndFeelException e) {}
		
 
		//Create the frame
		frame1 = new JFrame ("Loan Amortization Table");
		frame1.setSize (800,600);
		pane = frame1.getContentPane();
		insets = pane.getInsets();
		pane.setLayout (null);
		
		
		
		loan.createControls();
		
		//Add all components to panel
		pane.add (btnCalculate);
		pane.add (lblPrincipal);
		pane.add (lblAnnualInterestRate);
		pane.add (lblMonthlyPayment);
		pane.add (lblNumMonthlyPay);
		pane.add (lblTotalInterestPaid);
		pane.add (txtPrincipal);
		pane.add (txtAnnualInterestRate);
		pane.add (txtMonthlyPayment);
		pane.add (txtNumMonthlyPay);
		pane.add (txtTotalInterestPaid);
	  
	  //Place all the components such as the Labels, buttons, and text fields.
	
		
		lblPrincipal.setBounds (insets.left+5, insets.top+15, lblPrincipal.getPreferredSize().width, lblPrincipal.getPreferredSize().height);
		txtPrincipal.setBounds (insets.left+5, lblPrincipal.getY() + lblPrincipal.getHeight()+5, txtPrincipal.getPreferredSize().width, txtPrincipal.getPreferredSize().height);
		lblMonthlyPayment.setBounds(insets.left + 5, txtPrincipal.getY() + txtPrincipal.getHeight()+10,lblMonthlyPayment.getPreferredSize().width,lblMonthlyPayment.getPreferredSize().height);
		txtMonthlyPayment.setBounds(insets.left+5,lblMonthlyPayment.getY()+lblMonthlyPayment.getHeight()+5,txtMonthlyPayment.getPreferredSize().width,txtMonthlyPayment.getPreferredSize().height);
		lblAnnualInterestRate.setBounds(insets.left+5,txtMonthlyPayment.getY()+txtMonthlyPayment.getHeight()+10,lblAnnualInterestRate.getPreferredSize().width,lblAnnualInterestRate.getPreferredSize().height);
		txtAnnualInterestRate.setBounds(insets.left+5,lblAnnualInterestRate.getY()+lblAnnualInterestRate.getHeight()+5,txtAnnualInterestRate.getPreferredSize().width,txtAnnualInterestRate.getPreferredSize().height);
		
		lblNumMonthlyPay.setBounds(insets.left+ 200,insets.top+15, lblNumMonthlyPay.getPreferredSize().width, lblNumMonthlyPay.getPreferredSize().height);
		txtNumMonthlyPay.setBounds(insets.left+ 200, lblNumMonthlyPay.getY()+ lblNumMonthlyPay.getHeight()+5, txtNumMonthlyPay.getPreferredSize().width, txtNumMonthlyPay.getPreferredSize().height);
		lblTotalInterestPaid.setBounds(insets.left+200,txtNumMonthlyPay.getY()+txtNumMonthlyPay.getHeight()+10, lblTotalInterestPaid.getPreferredSize().width,lblTotalInterestPaid.getPreferredSize().height);
		txtTotalInterestPaid.setBounds(insets.left+200,lblTotalInterestPaid.getY()+lblTotalInterestPaid.getHeight()+5,txtTotalInterestPaid.getPreferredSize().width,txtTotalInterestPaid.getPreferredSize().height);
	
	
		btnCalculate.setBounds(insets.left+100,insets.top+200,btnCalculate.getPreferredSize().width, btnCalculate.getPreferredSize().height);
		//Set frame visible
		frame1.setVisible (true);
		
		//Button's action
		btnCalculate.addActionListener(new btnCalculateAction()); //Register action
		
		
		
		
		

}

public static class btnCalculateAction implements ActionListener{
		public void actionPerformed (ActionEvent e){
			
		
			
	   
	   
	   
		
		
	   txtNumMonthlyPay.setText("");
	   txtTotalInterestPaid.setText("");
	  
		}


	}
   
	
}



Is This A Good Question/Topic? 0
  • +

Page 1 of 1