I am theoretically not new on Java, but a beginner on practice.
I am experimenting with JavaFX and to begin with, I am implementing a GUI where the window (Stage) has the size of the screen.
The problem: I want to use this screen size object which is type of Rectangle and named screenBorders in another class(called Second).
Here is my simple code:
public class Test extends Application
{
public static void main(String[] args)
{ launch(args);}
public static Rectangle screenBorders;
@Override
public void start(Stage primaryStage)
{
Group grp=new Group();
Scene sc = new Scene(grp);
primaryStage.setScene(sc);
primaryStage.show();
screenBorders= new Rectangle (
Screen.getPrimary().getBounds().getWidth(),
Screen.getPrimary().getBounds().getHeight()
);
Second second= new Second();
}
}
New file, new class
class Second extends Group
{
public Second ()
{
Rectangle second =new Rectangle(screenBorders.getWidth(), screenBorders.getHeight());
}
//code, code, code, don't know yet what code i will put...
}
In this second class, I can't catch/use the screensize defined in the first class.( I want to use screenBorders)
I've tried to declare screenBorders with public and static keyword in the first and main class called Test, thinking that it could be used anywhere in my package, but it does'not work.
Does anyone have an idea about how to link an object with other classes ?