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: Quick Java Number pad problems

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Quick Java Number pad problems

    Basically I am trying to finish code for a simple GUI number pad and I am having issues with the very last bit. When I click the decimal Button(buttonDot) I want it to drop the default 0 after the decimal point, and then when I press another number button I want it to go where the 0 was.

    public class ButtonListener implements ActionListener {   	
    		public void actionPerformed(ActionEvent arg0) {
    			JButton clickedOn = (JButton)arg0.getSource();
    			String s=label1.getText();
    			int length=s.length()-1;
    			int d=0;
     
    			if(decimal==false) {			
    				if(clickedOn == buttonDot) {
    					decimal=true;
    				}
     
    				else if(label1.getText()=="0.0"){
    					label1.setText(clickedOn.getText()+".0");	
    				} else {
    					s=label1.getText();
    					label1.setText(s.substring(0,length1)+clickedOn.getText()+s.substring(length-1,length+1));
    					d++;
     
    				}
    			}
     
    			if(decimal==true) {			
    				if(clickedOn == buttonDot) {
    					return;
    				}
     
    				if(label1.getText().substring(length-1,length)==".0"){
    					label1.setText(s.substring(0,length-1)+clickedOn.getText());
    					System.out.println("f");
    				}
    				else {
    					label1.setText(s+clickedOn.getText());
    					System.out.println("u");
    				}
    			}
    			if(clickedOn == clear) {
    				decimal=false;
    				label1.setText("0.0");
     
     
     
    		}
     
     
    		}
     
     
    	}
    }
    Thanks for any help you can give me.


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Quick Java Number pad problems

    Hello SkippyTHEpimp. Welcome to the Java Programming Forums.

    Can you please post all of your code so we can attempt to compile it.
    It looks like there are parts missing from the above code.

    Thanks.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. Quick, beginner-level Java question.
    By DHG in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 27th, 2011, 01:06 PM
  2. Quick easy Java question.
    By DHG in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 25th, 2011, 03:59 PM
  3. Java Dos Logic Test count all non increasing number
    By Jhovarie in forum Object Oriented Programming
    Replies: 3
    Last Post: January 13th, 2011, 03:28 PM
  4. Trying to write a Java OS for a course, myrad problems...
    By Tinito16 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: May 3rd, 2010, 02:51 AM
  5. problems with loop in Java App
    By dmonx in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 13th, 2010, 04:13 PM