Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
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