3 Replies - 377 Views - Last Post: 03 October 2012 - 03:45 AM Rate Topic: -----

#1 Sheldor  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-September 12

Question Calculator Application Displaying Numbers

Posted 24 September 2012 - 03:49 AM

Hi I am a beginner in Java and I am creating a Calculator Application.
I have the GUI displaying and if I click a digit it will display the digits but when I click two digits simultaneously just the last digit clicked will display.

I know I need to declare a String but I am not sure how to do this.

Any assistance would be greatly appreciated. :rolleyes:

This is my code for the method.
package calculator;

public class CalculatorController {

	private final CalculatorModel model;
	public String displayNumbers = ""; 

	public CalculatorController(CalculatorModel model) {
		this.model = model;
	}
	
	public void buttonPushed(String buttonLabel) {
		if (buttonLabel.equals("C")){
			model.setDisplay("0.");
		}
		
		else
			model.setDisplay(buttonLabel + "");
			
		}
		
	}






Is This A Good Question/Topic? 0
  • +

Replies To: Question Calculator Application Displaying Numbers

#2 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: Question Calculator Application Displaying Numbers

Posted 24 September 2012 - 03:55 AM

not very much to look at
what does setDisplay() do ?
What is buttonLabel ?
buttonLabel + "" is exactly the same thing as the original buttonLabel.
May be beside the setDisplay() method you also need a appendToDisplay() method.
Was This Post Helpful? 0
  • +
  • -

#3 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: Question Calculator Application Displaying Numbers

Posted 25 September 2012 - 11:47 PM

View PostSheldor, on 24 September 2012 - 04:19 PM, said:

Hi I am a beginner in Java and I am creating a Calculator Application.
I have the GUI displaying and if I click a digit it will display the digits but when I click two digits simultaneously just the last digit clicked will display.

I know I need to declare a String but I am not sure how to do this.

Any assistance would be greatly appreciated. :rolleyes:

This is my code for the method.
package calculator;

public class CalculatorController {

	private final CalculatorModel model;
	public String displayNumbers = ""; 

	public CalculatorController(CalculatorModel model) {
		this.model = model;
	}
	
	public void buttonPushed(String buttonLabel) {
		if (buttonLabel.equals("C")){
			model.setDisplay("0.");
		}
		
		else
			model.setDisplay(buttonLabel + "");
			
		}
		
	}






Well, it is very difficult to help you with just this method so I suggest you post your entire code as some methods which you have used here don't have any definition. So, once you post the entire code, we will certainly be in a better position to help you.

regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#4 Sheldor  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-September 12

Re: Question Calculator Application Displaying Numbers

Posted 03 October 2012 - 03:45 AM

I figured it out thank you for your help.

In future I will post up all the code.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1