-2

Is there a way i can reset(change) the code of the method void mouseClicked() ,initially defined in the code, after an if(condition) is verified ?

Example : if i had:

void mouseClicked(){
print("clicked1");
}



void draw(){
  if(frameRate>=1000) ----> 
  //redefine mouseClicked() method so that it will do 
  exit(); 
}
Mohamed Benmahdjoub
  • 1,270
  • 4
  • 19
  • 38
  • There are many ways to change the behavior of a program, but your code is not enough to give you good advice. Please create a [mcve]. – RealSkeptic Dec 27 '15 at 14:37
  • Are you looking for something like this http://stackoverflow.com/questions/11749409/replace-content-of-some-methods-at-runtime –  Dec 27 '15 at 14:41

2 Answers2

1

I dont know, if i understood you right :D You could use a global boolean:

private boolean b = false;   
void mouseClicked(){
   if(b == false){
      print("clicked1");
   } else {
      print("clicked2");
   }
}

void draw(){
  if(frameRate>=1000){
     b = true;
  } else {
     b = false;
  }
  exit(); 
}
FlowX
  • 102
  • 12
-1

I, by myself, would try it this way: Create an interface that has the function mouseclicked() .Now, in your Mouselistener, create a variable of the interface and when the mouseclicked function in Mouselistener is called, call mouseclicked in the linked interface variable. Now you can create some classes that all implement your interface, but act different when mouseclicked() is called Finally , by changing your variable in Mouselistener to one of this classes, you can achieve different actions

Let me know if this helped or if you need any further explanation