Results 1 to 20 of 31
Thread: Combine .setTranslateY with 'if'
- 01-13-2017, 02:07 PM #1
Senior Member
- Join Date
- Nov 2016
- Posts
- 163
- Rep Power
- 5
Combine .setTranslateY with 'if'
Im developing basic game. I want to make some events...
character.setTranslateY (50);
Java FX Code:if ( character.TranslateY.equals.50; ) { right.setVisible (false); }
- 01-13-2017, 02:35 PM #2
Re: Combine .setTranslateY with 'if'
if ( character.TranslateY.equals.50; ) {
There should not be a ; inside of the ()s
You need to understand what symbols are for methods and which ones are for variables.
For variables you need to know which ones are for objects and which ones are for primitives.
You can not call a method using a primitive.
A numeric literal like 50 can not be referenced: ... equals.50
A method needs () with its args inside of the ()sIf you don't understand my response, don't ignore it, ask a question.
- 01-13-2017, 02:42 PM #3
Senior Member
- Join Date
- Nov 2016
- Posts
- 163
- Rep Power
- 5
Re: Combine .setTranslateY with 'if'
To write confidition with simple integers is no problem.
int a = 10;
Java FX Code:if (a<12){ a++; }
There should be something like coordinate = 50;
But I dont know. And Im not familar how to insert parameter value for condition.
- 01-13-2017, 02:55 PM #4
Re: Combine .setTranslateY with 'if'
Have you read the API doc for the class with the setTranslateY method?
There should be something like coordinate = 50;
What are you trying to do? Can you explain in English?Last edited by Norm; 01-13-2017 at 03:30 PM.
If you don't understand my response, don't ignore it, ask a question.
- 01-13-2017, 03:29 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Re: Combine .setTranslateY with 'if'
Can I suggest not doing GUI stuff at the moment?
Write a simple text game using the command line, so you can get used to how Java methods work.
GUI frameworks require you to understand how Java works, and so are not something a beginner should be using.Please do not ask for code as refusal often offends.
** This space for rent **
- 01-13-2017, 03:38 PM #6
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: Combine .setTranslateY with 'if'
The JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 01-13-2017, 08:10 PM #7
Senior Member
- Join Date
- Nov 2016
- Posts
- 163
- Rep Power
- 5
Re: Combine .setTranslateY with 'if'
- 01-13-2017, 08:31 PM #8
Re: Combine .setTranslateY with 'if'
Sorry, I don't like using links. Post any response you have here.
If you don't understand my response, don't ignore it, ask a question.
- 01-13-2017, 08:42 PM #9
Senior Member
- Join Date
- Nov 2016
- Posts
- 163
- Rep Power
- 5
Re: Combine .setTranslateY with 'if'
- 01-13-2017, 08:45 PM #10
Re: Combine .setTranslateY with 'if'
Please respond to the questions in post#4 with text in this thread. Not images or videos.
If you don't understand my response, don't ignore it, ask a question.
- 01-13-2017, 08:51 PM #11
Senior Member
- Join Date
- Nov 2016
- Posts
- 163
- Rep Power
- 5
Re: Combine .setTranslateY with 'if'
One button have to become invisible, once it reach certain coordinates.
Once image reach those coordinates.
Java FX Code:character.setTranslateY (50); character.setTranslateX (0);
But I dont know how to use "if ( )" condition this time.
Because 'character.setTranslateY (50)' should be used as condition, but compilator dont likes it.
- 01-13-2017, 08:55 PM #12
Re: Combine .setTranslateY with 'if'
compilator dont likes it.
Also show the definitions for the variables used in the statement so we know what data type they are.
'character.setTranslateY (50)' should be used as conditionIf you don't understand my response, don't ignore it, ask a question.
- 01-13-2017, 09:06 PM #13
Senior Member
- Join Date
- Nov 2016
- Posts
- 163
- Rep Power
- 5
Re: Combine .setTranslateY with 'if'
Type missmatch: cannot convert from void to boolean.
Java FX Code:Image charak= new Image (new FileInputStream("head.jpg") ); ImageView character = new ImageView (charak); character.setTranslateY (0); character.setTranslateX (0);
What does the API doc say about the setTranslateY() method? What type of value does it return that could be used in an if statement?
I dont understand here. Docs even dont bother to show simple example.Last edited by asdfg; 01-13-2017 at 09:09 PM.
- 01-13-2017, 09:17 PM #14
Re: Combine .setTranslateY with 'if'
Type missmatch: cannot convert from void to boolean.
An if statement requires a boolean value.
What values do you want to compare with an if statement?
Java FX Code:ImageView character = new ImageView (charak);
What does the API doc say about the setTranslateY() method? What type of value does it return that could be used in an if statement?
Is there another method that returns a value that could be tested?
Why is there a link for the Translate class in your post?Last edited by Norm; 01-13-2017 at 09:20 PM.
If you don't understand my response, don't ignore it, ask a question.
- 01-13-2017, 09:23 PM #15
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: Combine .setTranslateY with 'if'
In the first code example I see nothing which would give that error.
In the first code example or document link I see no setTranslateX or setTranslateY methods.
Edit: The above statement is incorrect. I found the methods in the Node class.
And if the JavaDoc showed examples of everything it would be as big as the unabridged OED.
Regards,
JimLast edited by jim829; 01-14-2017 at 01:06 AM. Reason: Correction
The JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 01-14-2017, 12:31 AM #16
Re: Combine .setTranslateY with 'if'
Also posted at: https://coderanch.com/t/674837/java/setTranslateY
Strange the OP couldn't ask the question like it was asked there.If you don't understand my response, don't ignore it, ask a question.
- 01-14-2017, 01:04 AM #17
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: Combine .setTranslateY with 'if'
Ok. My earlier reply was incorrect. ImageView inherits from Node and Node has the get and set translate methods. I missed it the first time I was reading the java doc. However, set returns void (i.e. nothing) and get returns a double. So you can't use them as boolean values. So you would need to use them like this:
Java FX Code:if (character.getTranslateX() == 50) { // then do something. }
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 01-14-2017, 01:24 AM #18
Senior Member
- Join Date
- Nov 2016
- Posts
- 163
- Rep Power
- 5
Re: Combine .setTranslateY with 'if'
Do I really have formatted question so unclear? I even made a short-video.
- 01-14-2017, 01:51 AM #19
Re: Combine .setTranslateY with 'if'
This was left off the questions on this forum:
I want to write a code:
if character coordinates is Y=50 and X=0,If you don't understand my response, don't ignore it, ask a question.
- 01-14-2017, 02:37 AM #20
Senior Member
- Join Date
- Sep 2014
- Location
- MA, USA
- Posts
- 399
- Rep Power
- 7
Re: Combine .setTranslateY with 'if'
So, our friends at Coderanch gave away the solution - too bad
. Norm pretty much gave you the solution in post #4 already. As a night read you should check "Encapsulation" as well as "Getters and Setters". It is one of the fundamental concepts in OOP. JavaFX follows this concept very closely.
I do think that the proposed solution at coderanch is incorrect in the sense of the game though. I would think that you disable the down button for all cells on the lower line and generally disable the respective buttons on the outside lines.
So, did you figure out how to set the Button instances disabled?
Similar Threads
-
Combine Error
By cloud in forum EclipseReplies: 1Last Post: 12-07-2011, 10:26 AM -
Combine two S.O.P in one
By javauserjava in forum New To JavaReplies: 5Last Post: 04-05-2011, 07:27 AM -
can i combine this 2 code into one?
By reeveliew in forum New To JavaReplies: 3Last Post: 05-09-2010, 03:24 PM -
How can I do this? Combine variable.
By PeterFeng in forum New To JavaReplies: 5Last Post: 01-14-2009, 06:44 PM
Bookmarks