Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Syntax error

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Syntax error

    import 
    java.awt.event.ActionListener; 
    import java.awt.event.ActionEvent; 
    import javax.swing.JButton; 
     
    public class CalculatorEngine 
    							implements ActionListener { 
     
    		Calculator parent; //a reference to Calculator window 
    		char selectedAction = ' '; // +, -, /, or * 
     
    		double currentResult =0; 
     
    		// Constructor stores the reference to the Calculator 
    		// window in the member variable parent 
    		CalculatorEngine(Calculator parent){ 
     
    		this.parent = parent; 
    		} 
     
    		public void actionPerformed(ActionEvent e){ 
     
    		// Get the source of this action 
    		JButton clickedButton = (JButton) e.getSource(); 
    		String 
    		dispFieldText=parent.displayField.getText(); 
     
    		double displayValue=0; 
     
    		//Get the number from the text field 
    		// if it’s not empty 
    		if (!"".equals(dispFieldText)){ 
    		displayValue= Double.parseDouble(dispFieldText); 
    		}
    		Object src = e.getSource(); 
     
    		// For each action button memorise selected 
    		// action +, -, /, or *, store the current value 
    		// in the currentResult, and clean up the display 
    		// field for entering the next number 
     
    		if (src == parent.buttonPlus){ 
    		selectedAction = '+'; 
    		currentResult=displayValue; 
    		parent.displayField.setText(""
    		); 
    		} else if (src == parent.buttonMinus){ 
    		selectedAction = '-'; 
    		currentResult=displayValue; 
    		parent.displayField.setText(""
    		); 
    		}else if (src == parent.buttonDivide){ 
    		selectedAction = '/'; 
    		currentResult=displayValue; 
    		parent.displayField.setText(""
    		); 
    		} else if (src == parent.buttonMultiply){ 
    		selectedAction = '*'; 
    		currentResult=displayValue; 
    		parent.displayField.setText(""
    		); 
    		} else if (src == parent.buttonEqual){ 
    		// Perform the calculations based on selectedAction 
    		// update the value of the variable currentResult 
    		// and display the result 
    		if (selectedAction=='+'){ 
    		currentResult+=displayValue; 
    		// Convert the result to String by concatenating 
    		// to an empty string and display it 
    		parent.displayField.setText(""+currentResult
    		); 
    		}else if (selectedAction=='-'){ 
    		currentResult -=displayValue; 
    		parent.displayField.setText(""+currentResult); 
    		}else if (selectedAction=='/'){ 
    		currentResult 
    		/=displayValue; 
    		parent.displayField.setText(""+currentResult); 
    		}else if (selectedAction=='*'){ 
    		 currentResult*=displayValue; 
    		parent.displayField.setText(""+currentResult); 
    		} 
    		} else{ 
    		// For all numeric buttons append the button's 
    		// label to the text field 
    		String clickedButtonLabel= 		clickedButton.getText(); 
    		parent.displayField.setText(dispFieldText +                                   <<<<This is where the error is
     
    		}
    		}
    }
    		clickedButtonLabel);

    The error is towards the bottom on the dispFieldText it says there is a syntax error, any ideas?


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Syntax error

    Please post the whole error, copied from just as it appears at your end and pasted into your post. Either update your original or add a new reply.

Similar Threads

  1. Syntax error on Token else?
    By SgtGarrison in forum Loops & Control Statements
    Replies: 15
    Last Post: March 20th, 2013, 06:26 AM
  2. Please help not sure how to get past the Syntax error
    By KnightC in forum Other Programming Languages
    Replies: 2
    Last Post: December 23rd, 2011, 10:09 AM
  3. MySQL Syntax Error
    By tarkal in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 30th, 2011, 03:29 PM
  4. Syntax error with dispose()
    By jagnat in forum AWT / Java Swing
    Replies: 1
    Last Post: October 14th, 2011, 11:00 AM
  5. do while syntax error problem
    By derekxec in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 1st, 2011, 06:30 PM