how to reset or change value of final variable?

Hi, Thank you at before.

Now I mean another problem.

I do sequential explanation.

http://cfile25.uf.tistory.com/image/125E6C4251488740021345

First. the Virus Panel Clicked.

http://cfile4.uf.tistory.com/image/0252FA4251488740138A19

Second. that opposite add Green Ground(Y-95 location).

Third. Green Ground(in Y-95) was clicked by mouse.

http://cfile4.uf.tistory.com/image/273AB34251488740342F0B

Fourth. Virus Panel move Y-95(forward).

http://cfile24.uf.tistory.com/image/124E9042514887411A2439

Fifth. the Link Panel Clicked.

Sixth. that opposite add Green Ground(Y-95 location).

Seventh. seem third. (Green Ground(in Y-95) was clicked by mouse.)

http://cfile1.uf.tistory.com/image/1615A73E51488836129FD3

Eighth. Virus Panel move Y-95(forward)

originally, if Link Panel clicked by mouse, Link Panel go forward.

but Link Panel not moved instead of Virus Panel moved.

I think due final JPanel mvp. but, can’t remove final.

The eclipes have necessary final.

so, I think. Not used final variable, error don’t get out.

but it not possible. Used final variable, enable reset final variable or change value(address value) of final variable.

how to do?


class Object{
 public static void main(String[] arg){
  JPanel Virus = new JPanel(15,15,80,80);
  JPanel Link = new JPanel(30,30,80,80);
  Virus.visible(true);
  Link.visible(true);
   Virus.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
     Moving mv= new Moving();
     mv.move_AE(Virus);
   }
  });
   Link.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
     Moving mv= new Moving();
     mv.move_AE(Link);
   }
  });
 }
}

class Moving{
 public void move_AF(JPanel mvp){
  if(!(Virus.getY()<=123)){
   move_N.setLocation(mvp.getX(), mvp.getY()-95); //Green Ground.
   move_N.setVisible(true);				
  }
 }
 public void move_AE(final JPanel mvp){
  move_N.addMouseListener(new MouseAdapter() {
   public void mouseClicked(MouseEvent e) {
    if(event){       
     move_set();
     mvp.setLocation(mvp.getX(), mvp.getY()-95); // mvp(Virus or Link) is going forward
     mvp.setVisible(true);
     event=false;
    }
   }
  });
 }
}

Declaring a variable as ‘final’ does not matter here because you don’t reassign it.
I can only guess that problem is in (member) variable ‘event’.

code and image added so, you review.

And completely Green Ground do work.

but move_method don’t well do.

So, I think, have a problem with ‘final’

Do you really want to add new listener on every call of move_AE() ?

“final” variables can not be changed or reset.

Sometimes it makes sense to make a new instance of the object that contains the final variable, but I don’t know that this would be a help here.