selectinput() in a class

edited November 2013 in Programming Questions

hi all

i want to use the fonction "selectinput()'' in a class but it still not work if is not in a class all its ok but not in class

the error said: "fileSelected() could not be found" but yet it is in my class

this is the part of my class

void mp3Parametre() {
  float mx = 30, my = 40,x1=40,y1=50,x2=40,y2=90,x3=40,y3=130,x4=40,y4=170;
  float masterRectSizeX = 200, masterRectSizeY = 175, rectSizeX = 180, rectSizeY = 30;
  float String1 = textWidth(file0_());
  //float xpos = 75;
  //int speed = 1;
  float test10;

 if(tcurState == 0){
   setMp3boolClose_(1);}

  pushStyle();

          stroke(255);
          strokeWeight(2);
          fill(100);
          rect(mx,my,masterRectSizeX,masterRectSizeY,7);
          pushMatrix();
          fill(50);

          rect(x1,y1,rectSizeX,rectSizeY,7);
          pushStyle();
          fill(255);
          textAlign(CENTER);
         //if(String1 > x1) {
           text(file0_(),xpos_(),my+y1-20);

          //setXpos_(-speed_());

          //else{text(file0_(),mx+x1+7,my+y1-20); }

          if(xpos_()<20){
           setXpos_(250); }  

          popStyle();
         // println(xpos_());

          rect(x2,y2,rectSizeX,rectSizeY,7);
          pushStyle();
          fill(255);
          textAlign(CENTER);
          text(file1_(),mx+x2+7,my+y2-20);
          popStyle();

          rect(x3,y3,rectSizeX,rectSizeY,7);
          pushStyle();
          fill(255);
          textAlign(CENTER);
          text(file2_(),mx+x3+7,my+y3-20);
          popStyle();

          rect(x4,y4,rectSizeX,rectSizeY,7);
          pushStyle();
          fill(255);
          textAlign(CENTER);
          text(file3_(),mx+x4+7,my+y4-20);
          popStyle();


          popStyle();
          pushStyle();

          if(overRect(fidposScreenX_()+x1,fidposScreenY_()+y1,rectSizeX,rectSizeY) && (tcurState_() == 1)) {
          fill(255);
          rect(x1,y1,rectSizeX,rectSizeY,7);
        // setFilebool1_(1);
          selectInput("Select a file to process:", "fileSelected1");
          setMp3bool_(0);
          setFidParamColor_(255,255,255,230);
        }

         popStyle(); 
         pushStyle();
          if(overRect(fidposScreenX_()+x2,fidposScreenY_()+y2,rectSizeX,rectSizeY) && (tcurState_() == 1)) {
            fill(255);
            rect(x2,y2,rectSizeX,rectSizeY,7);
            selectInput("Select a file to process:", "fileSelected2");
            setMp3bool_(0);
            setFidParamColor_(255,255,255,230);
          }
          popStyle();
          pushStyle();
          if(overRect(fidposScreenX_()+x3,fidposScreenY_()+y3,rectSizeX,rectSizeY) && (tcurState_() == 1)) {
            fill(255);
            rect(x3,y3,rectSizeX,rectSizeY,7);
            selectInput("Select a file to process:", "fileSelected3");
            setMp3bool_(0);
            setFidParamColor_(255,255,255,230);
          }
          popStyle();
          pushStyle();
          if(overRect(fidposScreenX_()+x4,fidposScreenY_()+y4,rectSizeX,rectSizeY) && (tcurState_() == 1)) {
            fill(255);
            rect(x4,y4,rectSizeX,rectSizeY,7);
            selectInput("Select a file to process:", "fileSelected4");
            setMp3bool_(0);
            setFidParamColor_(255,255,255,230);
          }
          if(overRect1(mx+fidposScreenX_(),my+fidposScreenY_(),200,175) && (tcurState_() == 1) && (mp3BoolClose_() == 1)) {
           setMp3bool_(0);
           setMp3boolClose_(0); 
           setFidParamColor_(255,255,255,230); }

          else{ setCloseParamColor_(255,255,255,230);
                setCloseParamRectColor_(50); }

          popStyle();
          popMatrix();

  }
//---------------------------------------------------------------------
void fileSelected1(File selection) {
  if (selection == null) {
    println("Window was closed or the user hit cancel.");
  } else {
    println("User selected " + selection.getPath());
    setPdFilePath1_(join(split(selection.getPath(), '\\'), "/"));
    setFilebool1_(1);
  }
}
//---------------------------------------------------------------------
void fileSelected2(File selection) {
  if (selection == null) {
    println("Window was closed or the user hit cancel.");
  } else {
    println("User selected " + selection.getPath());
    setPdFilePath2_(join(split(selection.getPath(), '\\'), "/"));
    setFilebool2_(1);
  }
}
//---------------------------------------------------------------------
void fileSelected3(File selection) {
  if (selection == null) {
    println("Window was closed or the user hit cancel.");
  } else {
    println("User selected " + selection.getPath());
    setPdFilePath3_(join(split(selection.getPath(), '\\'), "/"));
    setFilebool3_(1);
  }
}
//---------------------------------------------------------------------
void fileSelected4(File selection) {
  if (selection == null) {
    println("Window was closed or the user hit cancel.");
  } else {
    println("User selected " + selection.getPath());
    setPdFilePath4_(join(split(selection.getPath(), '\\'), "/"));
    setFilebool4_(1);
  }
}

someone know how to resolve this problem ?

Answers

  • edited November 2013

    Both selectInput() & selectFolder() pre-assumes that the method to invoke
    belongs to the sketch's main top-class; not 1 of our own classes!

    Only regular explanation is provided in the references: :-L
    http://processing.org/reference/selectInput_.html

    I've tried to decipher how to do it, registering my own class' reference; but failed! b-(
    It says fileSelected() must be public? :O)

    // forum.processing.org/two/discussion/1418/selectinput-in-a-class
    
    void setup() {
      noLoop();
      new InputTest();
    }
    
    class InputTest {
      String path;
    
      InputTest() {
        selectInput("Select a file to process:", "fileSelected", null, this);
      }
    
      void fileSelected(File selection) {
        if (selection == null)
          println("Window was closed or the user hit cancel.");
    
        else if (!selection.isFile())
          println("\"" + selection + "\" is an invalid file.");
    
        else
          println("User selected " + (path = selection.getAbsolutePath()));
      }
    }
    
  • at least you got a message other than "fileSelected() not found" but anyway it not solves my problem. you bring me another perspective I will try something else waiting to solve my problem. I try to put public before the void but without result. I also try to import the library "java.io.File;" and "java.util *,." but without success either. if someone has another solution I'm interested thank you a +

  • edited November 2013

    Ok I finally found the solution. it's just to put "public" in front of class eg: public class InputTest {}

    thx for your help a+

    // forum.processing.org/two/discussion/1418/selectinput-in-a-class
    
    void setup() {
      noLoop();
      new InputTest();
    }
    
    public class InputTest {
      String path;
    
      InputTest() {
        selectInput("Select a file to process:", "fileSelected", null, this);
      }
    
      void fileSelected(File selection) {
        if (selection == null)
          println("Window was closed or the user hit cancel.");
    
        else if (!selection.isFile())
          println("\"" + selection + "\" is an invalid file.");
    
        else
          println("User selected " + (path = selection.getAbsolutePath()));
      }
    }
    
  • edited November 2013

    Wow, I've thought Processing's pre-processor stamped public in everything w/o 1! @-)
    Seems like class is 1 of the exceptions; besides failing to do so in anonymous instantiations inside methods. :-\"
    But I still think that error can be averted w/ some patch fix from devs?! ^:)^

Sign In or Register to comment.