Jump to content

JavaFX


Recommended Posts

Posted

JavaFX applications need a no-args constructor and the controller class doesn't take the argument and act as a controller for some reason

 

I see, I've never touched JavaFX so I'm not exactly sure how to do this the best way.

Have you seen this? http://stackoverflow.com/questions/30814258/javafx-pass-parameters-while-instantiating-controller-class

 

Alternatively, if you don't really care about the code design you could just have a static getter in your main class, or in some sort of data class.

Posted (edited)
// don't forget the manifest
public class Unicorns extends Script {

    public static Script script;

    @ Override
    public void onStart() {
        script = this;
    }
    
    @ Override
    public int onLoop() {
        return 69;
    }

}

This wonderful piece of code solves all your OOP problems

Edited by Token
Posted (edited)

I see, I've never touched JavaFX so I'm not exactly sure how to do this the best way.

Have you seen this? http://stackoverflow.com/questions/30814258/javafx-pass-parameters-while-instantiating-controller-class

 

Alternatively, if you don't really care about the code design you could just have a static getter in your main class, or in some sort of data class.

 

Alright, well I can't pass arguments to the Controller/Test classes properly so I'll have to do that. How can I go about doing that because it won't let me reference Script from a static context

 

// don't forget the manifest
public class Unicorns extends Script {

    public static Script script;

    @ Override
    public void onStart() {
        script = this;
    }
    
    @ Override
    public int onLoop() {
        return 69;
    }

}
This wonderful piece of code solves all your OOP problems

 

I think I'm retarded

Edited by Orient
  • Like 1
Posted
// don't forget the manifest
public class Unicorns extends Script {

    public static Script script;

    @ Override
    public void onStart() {
        script = this;
    }
    
    @ Override
    public int onLoop() {
        return 69;
    }

}

This wonderful piece of code solves all your OOP problems

 

 

Feel like starting a debate so Ill go ahead and say that I wouldn't call it wonderful, bad code design and lack of encapsulation.

 

Your turn.

Posted

Well, there's really no alternative in this case unless you can somehow pass a constructor to an application class to retrieve the Script methods.

 

As a further note, I don't think you should be accessing Script methods in your JavaFX, instead of creating a Script instance, create a Unicorns instance (as demonstrated in @@Token's demonstration) and use that to pass the needed data into main.

Just a thought, don't have to do it but I think its better practice

  • Like 1
Posted (edited)

As a further note, I don't think you should be accessing Script methods in your JavaFX, instead of creating a Script instance, create a Unicorns instance (as demonstrated in @@Token's demonstration) and use that to pass the needed data into main.

Just a thought, don't have to do it but I think its better practice

 

Well, I'm just grabbing things like name among other things, I just needed to gain access to those

 

Nope, still retarded. Just going to pull the data from a separate class like a good little boy. Don't know what I'm talking about.

Edited by Orient

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...