Page 2 of 2 FirstFirst 12
Results 21 to 31 of 31
Like Tree2Likes

Thread: Combine .setTranslateY with 'if'

  1. #21
    asdfg is offline Senior Member
    Join Date
    Nov 2016
    Posts
    163
    Rep Power
    3

    Default Re: Combine .setTranslateY with 'if'

    If I were just straight, cope-pasted that code piece to my full code, then yes - it wouldnt work.

  2. #22
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    19,993
    Rep Power
    32

    Default Re: Combine .setTranslateY with 'if'

    that code piece to my full code
    What statement(s) did you code that worked?
    If you don't understand my response, don't ignore it, ask a question.

  3. #23
    asdfg is offline Senior Member
    Join Date
    Nov 2016
    Posts
    163
    Rep Power
    3

    Default Re: Combine .setTranslateY with 'if'

    Java FX Code:
               iVirsu = new Button ("Up");
    	        iVirsu.setTranslateY (220);
    	        iVirsu.setTranslateX (355);
    	        iVirsu.setOnAction (e -> 
    	        {
    	        	moveDownUp.set (moveDownUp.get() -50);
    	        	character.setTranslateY ( moveDownUp.get() );
    	        	
    	        	if (moveDownUp.get() == -250 ){			
    	        		iVirsu.setVisible (false);
    	        	}
    	        	if (moveDownUp.get() != 50 ) {
    	        		iApacia.setVisible (true);
    	        	}										
    	        });
    	       
    	        
    	        iApacia = new Button ("Down");
    	        iApacia.setTranslateY (310);
    	        iApacia.setTranslateX (355);
    	        iApacia.setOnAction (e -> 
    	        {
    	        	moveDownUp.set (moveDownUp.get() +50);
    	        	character.setTranslateY (moveDownUp.get() );
    	            
    	        	if (moveDownUp.get() == 50 ) {			
    		        	iApacia.setVisible (false);
    	        	}	
    	            if (moveDownUp.get() != -250 ) {
    	            	iVirsu.setVisible (true);			
    	            }								
    	        });

  4. #24
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    19,993
    Rep Power
    32

    Default Re: Combine .setTranslateY with 'if'

    That code is very, very different from:
    if (character.getTranslateY() == 50)
    or
    if ( character.TranslateY.equals.50; ) {

    Question:
    When is value returned by: moveDownUp.get()
    different from value returned by: character.getTranslateY()
    Last edited by Norm; 01-14-2017 at 03:45 PM.
    If you don't understand my response, don't ignore it, ask a question.

  5. #25
    asdfg is offline Senior Member
    Join Date
    Nov 2016
    Posts
    163
    Rep Power
    3

    Default Re: Combine .setTranslateY with 'if'

    moveDownUp cannot be returned, because it is SimpleIntegerProperty.
    If character reach the 'bottom border', then button 'down' becomes invisible.
    But if user clicks on 'Up' button - button 'down' becomes visible again.

  6. #26
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    19,993
    Rep Power
    32

    Default Re: Combine .setTranslateY with 'if'

    My question was about having two different variables that always contain the same value.
    What is the need for two variables when one will do it?
    If you don't understand my response, don't ignore it, ask a question.

  7. #27
    asdfg is offline Senior Member
    Join Date
    Nov 2016
    Posts
    163
    Rep Power
    3

    Default Re: Combine .setTranslateY with 'if'

    Quote Originally Posted by Norm View Post
    My question was about having two different variables that always contain the same value.
    What is the need for two variables when one will do it?
    Java FX Code:
    SimpleIntegerProperty moveHorizontal;
    SimpleIntegerProperty moveDownUp;
    I want that character to be capable to talk vertical and horizontal. Then it should have 2x SimpleIntegerProperty.
    Even if it would be possible to make with one- then it would be very complicated.
    ALso I cant image how it would look.

  8. #28
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    19,993
    Rep Power
    32

    Default Re: Combine .setTranslateY with 'if'

    Yes, there would be two variables, one for each direction.
    Now the code has 4 variables, two for each direction.
    If you don't understand my response, don't ignore it, ask a question.

  9. #29
    asdfg is offline Senior Member
    Join Date
    Nov 2016
    Posts
    163
    Rep Power
    3

    Default Re: Combine .setTranslateY with 'if'

    Java FX Code:
    if ( moveDownUp.get() == 0 && moveHorizontal.get() == 300 )		
    				{
    		        		Desine.setVisible(false);
    		        	}
    	
    
    		        	if ( moveDownUp.get() == -50 && moveHorizontal.get() == 300 )
    				{
    		        		Desine.setVisible(false);
    		        	}
    	
    
    		        	if ( moveDownUp.get() == -100 && moveHorizontal.get() == 300 )  
    				{
    		        		Desine.setVisible(false);
    		        	}
    This code doing fine. Can it be more compact?

    I tried this:

    Java FX Code:
    if ( moveHorizontal.get() == 300 &&  moveDownUp.get() == 0 || moveDownUp.get() == -50 ||
    			moveDownUp.get() == -100) {
    		Desine.setVisible (false);
    	}
    The problem is- that this code sometimes applies only 1 condition, and 'moveHorizontal.get() == 300' is being ignored.Combine .setTranslateY with 'if'-explain.png
    Red condition must to apply. One of the green condition have to be along red one.

  10. #30
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    19,993
    Rep Power
    32

    Default Re: Combine .setTranslateY with 'if'

    Sorry, I don't see how that relates to my question:
    moveDownUp.get() vs character.getTranslateY()

    Are you saying
    there are times when the value returned by moveDownUp.get() is different from the value returned by character.getTranslateY()?

    is being ignored.
    What does that mean? With the && operator, both conditions must be true for the full expression to be true.

    Debug with some print statements to see which conditions are true and which statements are executed.

    Can it be more compact?

    I tried this:
    Try using ()s to control the order of evaluation of the compound expression:
    ... == 300 && ( ... == 0 || ... == -50 || ... == -100)
    Last edited by Norm; 01-14-2017 at 08:00 PM.
    If you don't understand my response, don't ignore it, ask a question.

  11. #31
    asdfg is offline Senior Member
    Join Date
    Nov 2016
    Posts
    163
    Rep Power
    3

    Default Re: Combine .setTranslateY with 'if'

    Quote Originally Posted by Norm View Post
    Sorry, I don't see how that relates to my question:
    moveDownUp.get() vs character.getTranslateY()

    Are you saying
    there are times when the value returned by moveDownUp.get() is different from the value returned by character.getTranslateY()?
    I dont know what to answer, actually.
    Quote Originally Posted by SurfMan View Post
    These SimpleXXXProperty objects are used in binding. A term in JavaFX that you really need to know. As soon as the value of the property changes, the other object that it is bound to will be updated. JavaFX uses Binding and Observables extensively.

    Helpful link: Using JavaFX Properties and Binding | JavaFX 2 Tutorials and Documentation

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Combine Error
    By cloud in forum Eclipse
    Replies: 1
    Last Post: 12-07-2011, 09:26 AM
  2. Combine two S.O.P in one
    By javauserjava in forum New To Java
    Replies: 5
    Last Post: 04-05-2011, 06:27 AM
  3. can i combine this 2 code into one?
    By reeveliew in forum New To Java
    Replies: 3
    Last Post: 05-09-2010, 02:24 PM
  4. How can I do this? Combine variable.
    By PeterFeng in forum New To Java
    Replies: 5
    Last Post: 01-14-2009, 05:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •