lundi 9 mars 2020

How to simplify java if statements actionperformed?

I am wondering if the following code can be simplified somehow or no, because right now I only have 6 items but it is already getting too long for an if statement I think, and I will have more items as well. So if anyone knows a way how this code could be done a bit neater would help me a lot.

public void actionPerformed(ActionEvent e) {

       if(e.getSource() == filtering[0]){
         ImageFiltering(0);
       }
       else if(e.getSource() == filtering[1]){
         ImageFiltering(1);
       }
       else if(e.getSource() == filtering[2]){
         ImageFiltering(2);
       }
       else if(e.getSource() == filtering[3]){
         ImageFiltering(3);
       }
       else if(e.getSource() == filtering[4]){
         ImageFiltering(4);
       }
       else if(e.getSource() == filtering[5]){
         ImageFiltering(5);
       }
}



Aucun commentaire:

Enregistrer un commentaire