This discussion is archived
2 Replies Latest reply: Mar 15, 2013 1:21 AM by 864977 RSS

question about porting from javafx 1.3 to javafx 2.2

864977 Newbie
Currently Being Moderated
I think that better you porting all of example (javafx 1.3) to javafx 2.2 (my mean is all of example that there was in the javafx.com).
however, i have a question:
at javafx 1.3 we have this example:
<pre>
public abstract class AbstractView extends CustomeNode{
public String authID;
public Boolean show = false on replace{
if(show){
visible=true;
}else{
visible=false;
}
};
}
</pre>
i converted as:
<pre>
public abstract class AbstractView extends Node{
public String authID;
public static BooleanProperty show = new SimpleBooleanProperty(false) ;
private void AbstractView(){
if(show.get()) {
show.set(true);
} else {
show.set(false);
}
}
}
</pre>
can you tell me , Whether is this true or not?
  • 1. Re: question about porting from javafx 1.3 to javafx 2.2
    jsmith Guru
    Currently Being Moderated
    Your JavaFX 2 code is wrong, the original 1.3 code was toggling the visibility of the Node, but your JavaFX 2 code was not.
    Additionally a private constructor in a class which is never instantiated internally means that the class could never be used.
    When posting code it is a good idea to wrap the posted code in code tags (see the sticky thread at the top of the forums for more info).
    A straight conversion is probably something like below:
    public abstract class AbstractView extends Node {
      public String authID;
      public void AbstractView() {
        if (show.get()) {
          setVisible(true)
        } else {
          setVisible(false);
        }
      }
    }
    Attempting to do one-to-one code conversion of code between languages doesn't always render the cleanest code.
    Instead, I'd probably write it in Java as:
    public class AbstractView extends Node {
      private final String authID;
    
      public AbstractView(final String authID) {
        this.authID = authID;
        setVisible(false);
      }
    
      public String getAuthID() {
        return authID;
      }
    }
    I got rid of the show property as it seems to correspond exactly to the inbuilt visible property on the node, so it would appear to be redundant, when the existing setVisible(boolean), getVisible() and visibleProperty() can be used instead.
    I got rid of the abstract specifier on the class as there were no abstract methods in it.
    I made authID private as members are usually private when most people write Java code (though they don't necessarily need to be).
    I made authID final as it's usually a good idea to make everything final unless you know it needs to be a variable.
    I added a getter for authID so that it's value could be retrieved.
    The modified class isn't going to be interface wise exactly the same as the original JavaFX 1.3 class, but then no port of code between two dissimilar languages is.

    I'd advise spending some time going through the Java Tutorial trails covering Java Basics to get the basics of the Java language down.
    http://docs.oracle.com/javase/tutorial/
  • 2. Re: question about porting from javafx 1.3 to javafx 2.2
    864977 Newbie
    Currently Being Moderated
    ok, i understood about edit the code as correctly.
    My mean was all of example that was in the javafx.com (javafx 1.3).Examples would be a good learning

    i am using this code for visible or not visible an object.for example a notification or button.
    can you show me how should i calling this code for visible for example button?

    I think Syntax of Javafx 1.3 script was very easy but I really do not understand javafx2.2 !

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points