Home > Enterprise >  how do i call a method which has varibles but on mouse enter trigger with same varibles as orginal
how do i call a method which has varibles but on mouse enter trigger with same varibles as orginal

Time:12-29

I'm working on javafx in a 3d space and I'm creating a box out of rectangles in a method and when the mouse is over a rectangle as well as distance and a bunch of other variables it should repeat overall method with some variables which were passed. when all the variables are fulfilled it should repeat the method (overall) with variables from the original variables passed to the method (overall) but if the overall method is called once and then again while the one mouse entered is still waiting for mouse entered when the mouse entered is called it goes with the variables form the last time the method was called and not the variables that were set before the on mouse entered is called. How do I make the on mouse entered go with the variables that were stated in the method where the on mouse entered is called.

This sounds a bit long winded but I tried to explain it the best way I can. I want the on mouse entered statement to use the variables that were set with the on mouse entered. z is added 1 to the original position. `


 public void cb(String type, int x, int y, int z, int bn){

 Rectangle cube = new Rectangle(40,40),cube2 = new Rectangle(40,40),cube3 = new Rectangle(40,40),
        cube4 = new Rectangle(40.50195f,39.999f),cube5 = new Rectangle(39.9805f,39.9805f),cube6 = new Rectangle(39.9805f,39.9805f);  
  Group cubes = new Group(cube,cube2,cube3,cube4,cube5,cube6);
//this code is simplified to what i think is important//



     
       cube.setOnMouseEntered(event -> {
         
            me = true;
});

cube.setOnMouseExited(event -> {
    me = false;
   
    
});
final Point3D boxPosition = cube.localToScene(Point3D.ZERO);
            final Point3D cameraPosition = new Point3D(0,0,0);

final int bn2 = bn;
             final int xe = x;
 final int ye = y;
final int ze = z 1;
// tried using final//
// z needs to add 1//
       scene.setOnMouseClicked(event -> {
    if (event.getButton() == MouseButton.PRIMARY) {
          System.out.println(bn " t");
if(me== true){
      
     
            double distance = boxPosition.distance(cameraPosition);
           
            if(distance<250){
  
                    blocks = blocks   1;
           cb(type, xe, ye, ze,blocks);
          / this is where method is called again how do I make it use the set variables that
were set with the statement      /

            }     
}
                 }});


 }

call of method

      blocks = blocks 1;
cb("dirt", 1,2,4,blocks);
 blocks = blocks 1;
cb("dirt", 2,2,4, blocks);

`

CodePudding user response:

You can call the private method from outside the class by changing the runtime behaviour of the class.

With the help of java.lang.Class class and java.lang.reflect.Method class, we can call a private method from any other class.

Required methods of Method class

  1. public void setAccessible(boolean status) throws SecurityException sets the accessibility of the method.

  2. public Object invoke(Object method, Object... args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException is used to invoke the method.

Required method of Class class

  1. public Method getDeclaredMethod(String name,Class[] parameterTypes)throws NoSuchMethodException,SecurityException: returns a Method object that reflects the specified declared method of the class or interface represented by this Class object.
  • Related