K
K
krembrule20162018-12-10 11:32:13
Java
krembrule2016, 2018-12-10 11:32:13

How to move window graphical objects while the cursor is in a certain position?

Hello!
To make it clear, I will add here a picture with which I explained my problem to the infidels.
5c0e247427ed0887026104.png
On my own, I wrote the following code:

scene.setOnMouseMoved(e -> {
            System.out.println(e.getX()+" "+e.getY());

        if(e.getX()>750)
        {
          camera.cameraControlX(-0.5);
        }else if(e.getX()<50)
        {
          camera.cameraControlX(0.5);
        }
        if(e.getY()>550)
        {
          camera.cameraControlY(-0.5);
        }else if(e.getY()<50)
        {
          camera.cameraControlY(0.5);
        }

In the cameraControlX||Y function, I simply move the pictures around the scene. This works, but it only works while the cursor is in motion.
On stackoverflow, I was offered this option:
boolean north = false, east = false, south = false, west = false;

    scene.setOnMouseMoved(e -> {
        if(e.getX()>750)
        {
            east = true;
        }else if(e.getX()<50)
        {
            west = true;
        }else{
            east = false;
            west = false;
        }
        if(e.getY()>550)
        {
            south = true;
        }else if(e.getY()<50)
        {
            north = true;
        }else{
            north = false;
            south = false;
        }
    });
    AnimationTimer timer = new AnimationTimer() {
        @Override
        public void handle(long now) {
            if(east)camera.cameraControlX(-0.5);
            if(west)camera.cameraControlX(0.5);
            if(south)camera.cameraControlY(-0.5);
            if(north)camera.cameraControlY(0.5);
        }
    };
    timer.start();

But, the variables that we pass through the lambda, or just use an anonymous class, should not change their value. Should be final.
How to be? Which way to look?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
krembrule2016, 2018-12-15
@krembrule2016

If someone is interested in how I got out of the situation, then I just created the final object. Those. the logic is as follows: if you cannot change the value of the final variable in the lambda, then the properties of the object change twice.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question