Results 1 to 3 of 3
  1. #1
    custermd is offline Member
    Join Date
    Sep 2011
    Posts
    1
    Rep Power
    0

    Default ? issue with text box

    Any idea why this is not working. public void setResultValue2() should be putting data in the " textArea2.setText(Double.toString(result2));"
    Java Code:
    //public class week2 {
    	import javax.swing.*;
    
    	import java.awt.*;
    	import java.awt.event.*;
    	import java.text.*;
    	import java.util.EventObject;
    	import javax.swing.*;
    	import javax.swing.border.Border;
    import java.awt.*;
    	
    
    
    	// Creates class for class
    	public class week3o3 extends JFrame implements ActionListener
    	{
    		private static final long serialVersionUID = 8887922790267066604L;
    		// Radio Button Selection
    	JPanel rowOne = new JPanel();
    	JButton SELECTIONbutton1 = new JButton ("7 Years/5.35%");
    	JButton SELECTIONbutton2 = new JButton("15 Years/5.5%");
    	JButton SELECTIONbutton3 = new JButton("30 Years/5.75%");	
    	
    
    	
    	JPanel R2 = new JPanel();
    	JLabel PRINCIPLE = new JLabel("Principle Amount in Dollars:   ", JLabel.LEFT);
    	JTextField MORTGAGEpaymentTEXT = new JTextField(10);
    	JLabel TERMlabel = new JLabel("Mortgage Term in Years:   ", JLabel.LEFT);
    	JTextField TERMtextBOX = new JTextField(8);
    	JLabel INTERESTtextLABEL = new JLabel("Interest Rate Percentage:   ", JLabel.LEFT);
    	JTextField INTERESTrateTEXT = new JTextField(5);
    	JLabel MONTHLYpayLABEL = new JLabel("Monthly Payment $   ", JLabel.LEFT);
    	JTextField MPAYTEXT = new JTextField(10);
    
    	// Create buttons to calculate payment,exit and clear fields
    	JPanel BOTTOMrow = new JPanel();
    	JButton calcBu = new JButton("CALCULATE");
    	JButton clBu = new JButton("CLEAR");
    	JButton exBu = new JButton("EXIT");
    
    	public week3o3(){
    	super("CALCULATOR");
    	setSize(400,500);
    	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	Container pane = getContentPane();
    	FlowLayout layout = new FlowLayout (FlowLayout.CENTER);
    	pane.setLayout(layout);
    	
    	
    
    
    		// Add to the screen
    	FlowLayout layout1 = new FlowLayout();
    	rowOne.setLayout(layout1);
    
    		// Add Radio Button Group
    	ButtonGroup btnGrp = new ButtonGroup();
    	btnGrp.add(SELECTIONbutton1);
    	btnGrp.add(SELECTIONbutton2);
    	btnGrp.add(SELECTIONbutton3);
    	rowOne.add(SELECTIONbutton1);
    	rowOne.add(SELECTIONbutton2);
    	rowOne.add(SELECTIONbutton3);
    	pane.add(rowOne);
    
    		// Create a border around the radio buttons
    	Border titledRadioBorder =
    	BorderFactory.createTitledBorder("Choose one");
    	rowOne.setBorder(titledRadioBorder);
    
    		// Listeners
    	SELECTIONbutton1.addActionListener(this);
    	SELECTIONbutton2.addActionListener(this);
    	SELECTIONbutton3.addActionListener(this);
    		
    
    
    		
    		
    		
    	// text boxes and labels and places default values
    	GridLayout layout2 = new GridLayout (4, 1);
    	R2.setLayout(layout2);
    	R2.add(PRINCIPLE);
    	R2.add(MORTGAGEpaymentTEXT);
    	//MORTGAGEpaymentTEXT.setText("200000");
    	R2.add(TERMlabel);
    	R2.add(TERMtextBOX);
    	//TERMtextBOX.setText("30");
    	R2.add(INTERESTtextLABEL);
    	R2.add(INTERESTrateTEXT);
    	//INTERESTrateTEXT.setText("5.75");
    	R2.add(MONTHLYpayLABEL);
    	R2.add(MPAYTEXT);
    	MPAYTEXT.setEnabled(false);
    	pane.add(R2);
    	
    	
    	// Create Label for Text Box
    	JPanel rowFour = new JPanel();
    	JLabel paymentLabel = new JLabel ("Payment #");
    	JLabel balLabel = new JLabel (" Balance");
    	JLabel ytdPrincLabel = new JLabel (" Principal");
    	JLabel ytdIntLabel = new JLabel (" Interest");
    
    	// Display area
    	JPanel rowFive = new JPanel(new FlowLayout());
    	JTextArea textArea2 = new JTextArea(10, 31);
    	JScrollPane scroll = new JScrollPane(textArea2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, 
    	JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    	
    	
    	// Add Text Box Label
    	FlowLayout layout4 = new FlowLayout (FlowLayout.LEFT, 10, 10);
    	rowFour.setLayout (layout4);
    	rowFour.add(paymentLabel);
    	rowFour.add(balLabel);
    	rowFour.add(ytdPrincLabel);
    	rowFour.add(ytdIntLabel);
    	pane.add(rowFour);
    
    	// Add Text Box
    	FlowLayout layout5 = new FlowLayout (FlowLayout.CENTER, 10, 10);
    	rowFive.setLayout(layout5);
    	rowFive.add(scroll);
    	pane.add(rowFive);
    	setContentPane(pane);
    	setVisible(true);
    	
    	
    	
    	// format adding the buttons to the row   
    	FlowLayout LO3 = new FlowLayout (FlowLayout.CENTER, 10, 10);
    	BOTTOMrow.setLayout (LO3);
    	BOTTOMrow.add(calcBu);
    	BOTTOMrow.add(clBu);
    	BOTTOMrow.add(exBu);
    	pane.add(BOTTOMrow);
    
    	// listeners
    	calcBu.addActionListener(this);
    	clBu.addActionListener(this);
    	exBu.addActionListener(this);
    	setContentPane(pane);
    	setVisible(true);
    	}
    
    	public static void main(String[] args)throws ParseException {
    	       @SuppressWarnings("unused")
    		week3o3 frame = new week3o3();
    	}
    
    	public void setResultValue()
    	 {
    	   double PRINCIPLE = Double.parseDouble(MORTGAGEpaymentTEXT.getText());
    	   double term = Double.parseDouble(TERMtextBOX.getText());
    	   double rate = Double.parseDouble(INTERESTrateTEXT.getText()) / 100.;
    	   double result = (PRINCIPLE * ( rate/12))/(1-( Math.pow (1/( 1 +(rate/12)), (term*12))));
    	   //equation cited from [url=http://www.hughchou.org/calc/formula.html]Mortgage calculations -- how loan amortization works[/url]
    	   
    	   MPAYTEXT.setText(Double.toString(result));
    	}         
    	
    	public void setResultValue2()
    	{
    		double PRINCIPLE = Double.parseDouble(MORTGAGEpaymentTEXT.getText());
    		double term = Double.parseDouble(TERMtextBOX.getText());
    		double rate = Double.parseDouble(INTERESTrateTEXT.getText());
    		double result2 = (PRINCIPLE * ( rate/12))/(1-( Math.pow (1/( 1 +(rate/12)), (term*12))));
    	
    		//AbstractButton textArea2 = null;
    		//AbstractButton textArea = null;//*
    		textArea2.setText(Double.toString(result2));
    	
    	} 
    		
    	
    	public void actionPerformed(ActionEvent event) {
    		 if (event.getSource() == SELECTIONbutton1) {
    		    	MORTGAGEpaymentTEXT.setText("200000");;
    		    	MPAYTEXT.setText("");;
    		    	INTERESTrateTEXT.setText("5.35");;
    		    	TERMtextBOX.setText("7");;
    		    }
    		 if (event.getSource() == SELECTIONbutton2) {
    		  	    MORTGAGEpaymentTEXT.setText("200000");;
    		  	    MPAYTEXT.setText("");;
    		  	    INTERESTrateTEXT.setText("5.50");;
    		  	    TERMtextBOX.setText("15");;
    		    }
    		 if (event.getSource() == SELECTIONbutton3) {
    			  	 MORTGAGEpaymentTEXT.setText("200000");;
    			  	 MPAYTEXT.setText("");;
    			  	 INTERESTrateTEXT.setText("5.75");;
    			  	 TERMtextBOX.setText("30");;
    		    }
    		
    		if (event.getSource() == calcBu) {
    	        setResultValue();}
    	    
    	    if (event.getSource() == clBu) {
    	    	MORTGAGEpaymentTEXT.setText("");;
    	    	MPAYTEXT.setText("");;
    	    	INTERESTrateTEXT.setText("");;
    	    	TERMtextBOX.setText("");;
    	    }
    	Object command = event.getSource();
    		if (command == exBu){
    	System.exit(0);
    	}
    	}
    	}
    //code citations from http://forums.devx.com/showthread.php?t=166408
    Last edited by sunde887; 09-29-2011 at 04:50 PM.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default Re: ? issue with text box

    Is setResultValue2 ever called? Add some println statements in there to see

  3. #3
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,226
    Rep Power
    6

    Default Re: ? issue with text box

    Learn proper Java naming standards for variable names. I have never seen textbooks or any code posted on forums look like that.

Similar Threads

  1. Replies: 8
    Last Post: 07-17-2011, 02:38 PM
  2. Replies: 7
    Last Post: 03-05-2011, 09:25 AM
  3. Replies: 1
    Last Post: 01-21-2011, 11:46 AM
  4. JButton with Icon & text alignment issue
    By ShardaD in forum AWT / Swing
    Replies: 4
    Last Post: 01-11-2011, 11:10 AM
  5. Replies: 0
    Last Post: 12-09-2010, 05:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •