Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

java calculator program


  • Please log in to reply

#1
Thef0rce

Thef0rce

    Member

  • Member
  • PipPipPip
  • 380 posts
I currently have this code fragment in the eventhandler for when the user clicks on a button denoted with a string "." to represent the decimal point in a calculator gui program:

public void actionPerformed(java.awt.event.ActionEvent e) {
		
		JButton b = ( JButton )e.getSource();	
		
		String label = b.getText();
		 
		 
		//decimal handling
		//cannot have 2 decimals 
		
		if (label.equals(".")) {  
		
			String t1 = display.getText();
			
			if (t1.indexOf(".") == -1) 
				display.setText(t1 + ".");	
		}

However, this still allows for too many decimals, even though I do check for the existence of a decimal via the indexOf method. anyone have any idea why this is happening? The display that I'm displaying to is named display, the rest of the code is correct, I just can't get this decimal thing to work.

Thanks.
  • 0

Advertisements


#2
destin

destin

    Member

  • Member
  • PipPip
  • 53 posts
Can you post more code? The code that you posted there looks flawless; I have a feeling the bug is somewhere else.

Edited by destin, 03 March 2006 - 03:17 PM.

  • 0

#3
Thef0rce

Thef0rce

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 380 posts
solved. just missed out an else if. typical java :tazz:
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP