help on fixing error code

Java error code help PLEASE

Page 1 of 1

9 Replies - 1211 Views - Last Post: 05 October 2009 - 05:07 PM Rate Topic: -----

#1 javaidot  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 04-September 09

help on fixing error code

Post icon  Posted 05 October 2009 - 06:14 AM

can someone please look at the following code, I am getting one error on line 108
Java 108 ';' expected contentPane.add(outputJTextArea)

I do not know how to fix this.

import java.awt.*;
import java.awt.event.*;
import java.text.*;
import javax.swing.*;

public class MortgageCalculator extends JFrame
{
   // JLabel and JTextField for the mortgage amount
   private JLabel amountJLabel;
   private JTextField amountJTextField;

   // JLabel and JTextField for interest percentage rate
   private JLabel interestJLabel;
   private JTextField interestJTextField;

   // JTextArea for displaying results
   private JTextArea outputJTextArea;

   // JButton to initiate calculations
   private JButton calculateJButton;

   // no-argument constructor
   public MortgageCalculator()
   {
	  createUserInterface();
   }

   // create and position the GUI components; register event handlers
   private void createUserInterface()
   {
	  // get content pane for attaching GUI components
	  Container contentPane = getContentPane();

	  // enable explicit positioning of GUI components
	  contentPane.setLayout( null );

	  // set up amountJLabel
	  amountJLabel = new JLabel();
	  amountJLabel.setBounds( 16, 16, 104, 26 );
	  amountJLabel.setText( "Mortgage amount:" );
	  contentPane.add( amountJLabel );

	  // set up amountJTextField
	  amountJTextField = new JTextField();
	  amountJTextField.setBounds( 144, 16, 56, 26 );
	  amountJTextField.setHorizontalAlignment( JTextField.RIGHT );
	  contentPane.add( amountJTextField );
	  amountJTextField.addKeyListener(

		 new KeyAdapter() // anonymous inner class
		 {
			// event handler for key pressed in amountJTextField
			public void keyPressed( KeyEvent event )
			{
			   amountJTextFieldKeyPressed( event );
			}

		 } // end anonymous inner class

	  ); // end call to addKeyListener

	  // set up interestJLabel
	  interestJLabel = new JLabel( "Annual interest rate:" );
	  interestJLabel.setBounds( 16, 56, 115, 26 );
	  interestJLabel.setText( "Annual interest rate:" );
	  contentPane.add( interestJLabel);

	  // set up interestJTextField
	  interestJTextField = new JTextField();
	  interestJTextField.setBounds( 144, 56, 56, 26 );
	  interestJTextField.setHorizontalAlignment( JTextField.RIGHT );
	  contentPane.add( interestJTextField );
	  interestJTextField.addKeyListener(

		 new KeyAdapter() // anonymous inner class
		 {
			// evend handler for key pressed in interestJTextField
			public void interestJTextField( KeyEvent event )
			{
			   interestJTextFieldKeyPressed( event );
			}

		 } // end anonymous inner class

	  ); // end call to addKeyListener

	  // set up calculateJButton
	  calculateJButton = new JButton();
	  calculateJButton.setBounds( 224, 16, 90, 26 );
	  calculateJButton.setText( "Calculate" );
	  contentPane.add( calculateJButton );
	  calculateJButton.addActionListener(

		 new ActionListener() // anonymous inner class
		 {
			 // event handler called when calculateJButton is pressed
			 public void actionPerformed ( ActionEvent event )
			 {
				calculateJButtonActionPerformed( event );
			 }

		 } // end anonymous inner class

	  ); // end call to addActionListener

	  // set up outputJTextArea
	  outputJTextArea = new JTextArea(16, 96, 298, 110)
	  contentPane.add( outputJTextArea );
	  seteditable( false );

	  // set properties of application’s window
	  setTitle( "Mortgage Calculator" ); // set title bar text
	  setSize( 338, 250 );			   // set window's size
	  setVisible( true );				// display window

   } // end method createUserInterface

   // called when user presses key in amountJTextField
   private void amountJTextFieldKeyPressed( KeyEvent event )
   {
	  outputJTextArea.setText( "" );  // clear outputJTextArea
   }

   // called when user presses key in interestJTextField
   private void interestJTextFieldKeyPressed( KeyEvent event )
   {
	  outputJTextArea.setText( "" );  // clear outputJTextArea
   }

   // method called when user clicks calculateJButton
   private void calculateJButtonActionPerformed( ActionEvent event )
   {

   } // end method calculateJButtonActionPerformed

   // calculate monthlyPayment
   private double calculateMonthlyPayment( double monthlyInterest,
	  int months, int loanAmount )
   {
	  double base = Math.pow( 1 + monthlyInterest, months );
	  return loanAmount * monthlyInterest / ( 1 - ( 1 / base ) );
   }

   // main method
   public static void main( String[] args )
   {
	  MortgageCalculator application = new MortgageCalculator();
	  application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

   } // end method main

} // end class MortgageCalculator



This post has been edited by javaidot: 05 October 2009 - 07:25 AM


Is This A Good Question/Topic? 0
  • +

Replies To: help on fixing error code

#2 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: help on fixing error code

Posted 05 October 2009 - 06:19 AM

please edit your post and post your code like this
:code:
Was This Post Helpful? 0
  • +
  • -

#3 javaidot  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 04-September 09

Re: help on fixing error code

Posted 05 October 2009 - 08:52 AM

can anyone help me fix my error code? I cann't figure it out

error code is as followed:

C:\Users\bby\Desktop\MortgageCalculator.java:108: ';' expected
contentPane.add( outputJTextArea );
^
1 error

Tool completed with exit code 1


import java.awt.*;
import java.awt.event.*;
import java.text.*;
import javax.swing.*;

public class MortgageCalculator extends JFrame
{
   // JLabel and JTextField for the mortgage amount
   private JLabel amountJLabel;
   private JTextField amountJTextField;

   // JLabel and JTextField for interest percentage rate
   private JLabel interestJLabel;
   private JTextField interestJTextField;

   // JTextArea for displaying results
   private JTextArea outputJTextArea;

   // JButton to initiate calculations
   private JButton calculateJButton;

   // no-argument constructor
   public MortgageCalculator()
   {
	  createUserInterface();
   }

   // create and position the GUI components; register event handlers
   private void createUserInterface()
   {
	  // get content pane for attaching GUI components
	  Container contentPane = getContentPane();

	  // enable explicit positioning of GUI components
	  contentPane.setLayout( null );

	  // set up amountJLabel
	  amountJLabel = new JLabel();
	  amountJLabel.setBounds( 16, 16, 104, 26 );
	  amountJLabel.setText( "Mortgage amount:" );
	  contentPane.add( amountJLabel );

	  // set up amountJTextField
	  amountJTextField = new JTextField();
	  amountJTextField.setBounds( 144, 16, 56, 26 );
	  amountJTextField.setHorizontalAlignment( JTextField.RIGHT );
	  contentPane.add( amountJTextField );
	  amountJTextField.addKeyListener(

		 new KeyAdapter() // anonymous inner class
		 {
			// event handler for key pressed in amountJTextField
			public void keyPressed( KeyEvent event )
			{
			   amountJTextFieldKeyPressed( event );
			}

		 } // end anonymous inner class

	  ); // end call to addKeyListener

	  // set up interestJLabel
	  interestJLabel = new JLabel( "Annual interest rate:" );
	  interestJLabel.setBounds( 16, 56, 115, 26 );
	  interestJLabel.setText( "Annual interest rate:" );
	  contentPane.add( interestJLabel);

	  // set up interestJTextField
	  interestJTextField = new JTextField();
	  interestJTextField.setBounds( 144, 56, 56, 26 );
	  interestJTextField.setHorizontalAlignment( JTextField.RIGHT );
	  contentPane.add( interestJTextField );
	  interestJTextField.addKeyListener(

		 new KeyAdapter() // anonymous inner class
		 {
			// evend handler for key pressed in interestJTextField
			public void interestJTextField( KeyEvent event )
			{
			   interestJTextFieldKeyPressed( event );
			}

		 } // end anonymous inner class

	  ); // end call to addKeyListener

	  // set up calculateJButton
	  calculateJButton = new JButton();
	  calculateJButton.setBounds( 224, 16, 90, 26 );
	  calculateJButton.setText( "Calculate" );
	  contentPane.add( calculateJButton );
	  calculateJButton.addActionListener(

		 new ActionListener() // anonymous inner class
		 {
			 // event handler called when calculateJButton is pressed
			 public void actionPerformed ( ActionEvent event )
			 {
				calculateJButtonActionPerformed( event );
			 }

		 } // end anonymous inner class

	  ); // end call to addActionListener

	  // set up outputJTextArea
	  outputJTextArea = new JTextArea(16, 96, 298, 110)
	  contentPane.add( outputJTextArea );
	  seteditable( false );

	  // set properties of application’s window
	  setTitle( "Mortgage Calculator" ); // set title bar text
	  setSize( 338, 250 );			   // set window's size
	  setVisible( true );				// display window

   } // end method createUserInterface

   // called when user presses key in amountJTextField
   private void amountJTextFieldKeyPressed( KeyEvent event )
   {
	  outputJTextArea.setText( "" );  // clear outputJTextArea
   }

   // called when user presses key in interestJTextField
   private void interestJTextFieldKeyPressed( KeyEvent event )
   {
	  outputJTextArea.setText( "" );  // clear outputJTextArea
   }

   // method called when user clicks calculateJButton
   private void calculateJButtonActionPerformed( ActionEvent event )
   {

   } // end method calculateJButtonActionPerformed

   // calculate monthlyPayment
   private double calculateMonthlyPayment( double monthlyInterest,
	  int months, int loanAmount )
   {
	  double base = Math.pow( 1 + monthlyInterest, months );
	  return loanAmount * monthlyInterest / ( 1 - ( 1 / base ) );
   }

   // main method
   public static void main( String[] args )
   {
	  MortgageCalculator application = new MortgageCalculator();
	  application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

   } // end method main

} // end class MortgageCalculator



Was This Post Helpful? 0
  • +
  • -

#4 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: help on fixing error code

Posted 05 October 2009 - 09:05 AM

you have a missing semicolon at this line outputJTextArea = new JTextArea(16, 96, 298, 110); but then you will get another error since there's no such constructor for the JTextArea class

also please dont duplicate your posts, you already posted this question in another thread
Was This Post Helpful? 0
  • +
  • -

#5 NeoTifa  Icon User is online

  • Whorediot
  • member icon





Reputation: 2775
  • View blog
  • Posts: 15,875
  • Joined: 24-September 08

Re: help on fixing error code

Posted 05 October 2009 - 09:13 AM

Quote

outputJTextArea = new JTextArea(16, 96, 298, 110)


That doesn't have a ;

Crap, beat me to it...

This post has been edited by NeoTifa: 05 October 2009 - 09:14 AM

Was This Post Helpful? 0
  • +
  • -

#6 javaidot  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 04-September 09

Re: help on fixing error code

Posted 05 October 2009 - 09:43 AM

How do I fix that one? I greatly appreciate all your help



View Postmostyfriedman, on 5 Oct, 2009 - 08:05 AM, said:

you have a missing semicolon at this line outputJTextArea = new JTextArea(16, 96, 298, 110); but then you will get another error since there's no such constructor for the JTextArea class

also please dont duplicate your posts, you already posted this question in another thread

Was This Post Helpful? 0
  • +
  • -

#7 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: help on fixing error code

Posted 05 October 2009 - 09:49 AM

for that you will have to check the API and choose the most appropriate constructor for your application
Was This Post Helpful? 0
  • +
  • -

#8 NeoTifa  Icon User is online

  • Whorediot
  • member icon





Reputation: 2775
  • View blog
  • Posts: 15,875
  • Joined: 24-September 08

Re: help on fixing error code

Posted 05 October 2009 - 09:54 AM

http://java.sun.com/.../JTextArea.html

The constructor you are trying to access has 4 parameters, but doesn't exist. Try one of these:


[attachment=14197:attachment]

This post has been edited by NeoTifa: 05 October 2009 - 09:55 AM

Was This Post Helpful? 0
  • +
  • -

#9 syfran  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 83
  • View blog
  • Posts: 1,103
  • Joined: 12-July 09

Re: help on fixing error code

Posted 05 October 2009 - 03:10 PM

Thank you for the code tags and for pasting the content of the line the error its giving.

outputJTextArea = new JTextArea(16, 96, 298, 110)
contentPane.add( outputJTextArea );



Just like it said, It was expecting to see a semicolon, instead of another statement. Simple solution is to give it a semicolon :P


outputJTextArea = new JTextArea(16, 96, 298, 110);
contentPane.add( outputJTextArea );


Was This Post Helpful? 0
  • +
  • -

#10 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8343
  • View blog
  • Posts: 31,890
  • Joined: 06-March 08

Re: help on fixing error code

Posted 05 October 2009 - 05:07 PM

Duplicated topics merged
Pleaseavoid duplicated threads :angry:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1