The constructor is undefined...

Hi

I'm pretty frustrated with a piece of code.

I just copied and pasted this class and other functions into a new sketch called "Program_Drawer". I pasted it into a new tab called "Buttons".

class Button{
  int wid;
  int high;
  int xpos;
  int ypos;
  int point;
  String text;
  color shade;
  boolean isClickable;
  boolean isClicked = false;
 public Button(int w, int h, int x, int y, int pt, String txt, color c, boolean cl){
    wid=w;
    high=h;
    xpos=x;
    ypos=y;
    point=pt;
    text=txt;
    shade=c;
    isClickable=cl;
  }
  public boolean isUnder(Click clk){
    if(clk.x>(xpos-(wid/2)) && clk.x<(xpos+(wid/2)) && clk.y>(ypos-(high/2)) && clk.y<(ypos+(high/2))){
      return true;
    }
    else{
      return false;
    }
  }
}


boolean buttonIsPressed(int slot){
  if(buttons[slot].isClicked == true){
    return true;
  }
  else{
    return false;
  }
}

void makeButtonClickable(int slot){
  buttons[slot].isClickable = true;
}

void resetButtons(Button[] buts){
  for(Button but : buts){
    but.isClickable = false;
    but.isClicked = false;
  }
}

Button[] buttons = {new Button(200,40,WINDOW_WIDTH/2,(WINDOW_HEIGHT/2)+40,25,"Upload",color(0,0,255),false),
                    new Button(200,40,WINDOW_WIDTH/2,(WINDOW_HEIGHT/2)+80,25,"Flip",color(0,0,255),false),
                    new Button(200,40,WINDOW_WIDTH/2,(WINDOW_HEIGHT/2)+140,25,"Save",color(0,0,255),false),
                    new Button(200,40,WINDOW_WIDTH/2,(WINDOW_HEIGHT/2)+200,25,"Quit",color(255,95,95),false)};

As you can see, the constructor is there, same name. However, it stops compiling at buttons[] telling me The constructor Program_Drawer.Button(int,int,float,float,int,String,int,boolean) is undefined

I've tried placing the array declaration to different parts like setup, no luck.

I can't seem to find any help online.

Thanks for the help

Answers

  • edited September 2015 Answer ✓

    You're trying to pass the following signature: (int, int, float, float, int, String, int, boolean)

    However, Button constructor's signature is: (int, int, int, int, int, String, int, boolean)!

  • Thank you so much, I never would have seen that!

Sign In or Register to comment.