We are about to switch to a new forum software. Until then we have removed the registration on this forum.
class Slider
{
Slider mySlider ;
int x, y ,w=180,h = 10 ,rctx;
boolean locked ;
Slider (int x , int y ){
rctx=x;
this.x = x ;
this.y = y ;
locked = true ; }
void lock ()
{
locked = true ;
}
void unlock ()
{if (mouseX>=x-w/2 && mouseX<= x+w/2 &mouseY>= y-h/2 && mouseY<= y+h/2)
locked = false;
}
void drag()
{
if (locked==false)
{x=mouseX;
}
}
void display()
{
x=constrain (x,rctx,rctx+w);
rect(rctx,y,180,10);
fill(128,128,128);
ellipse(x,y,20,20);
}}
Slider mySlider ;
void setup()
{ size(300, 100);
mySlider = new Slider (10,10);
mySlider.lock();}
void draw()
{
background (255);
mySlider.display();
}
void mousePressed()
{
mySlider.unlock();}
void mouseDragged()
{
mySlider.drag();}
void mouseReleased()
{
mySlider.lock();}
Basic slider class and driver the code runs with a small window .For any value larger than (100 100) I get a weird message about size() cannot be used here .
Answers
consider using ctrl-t in processing to auto-format your code in processing
it runs for me though
for me it doesn't and really I have no idea why it doesn't .
What do you have in your other tab?
Kf
you got a second tab
what is in it ?
remember that tabs do not denote different sketches, but just different sections of one sketch that are stitched together when you run it
I have the slider class in the second tab
like you posted it above?
try to bring it all into one tab and delete the other
you have two times size I guess
no size in the class please
all } correct?
maybe setup needs to be in the tab with the file name?
i managed to reproduce it. and then i didn't.
i don't like Main as a tab name though.
For some reason ,on my machine only , the problem was recurring . Upon altering the code on another machine the code ran properly on my machine .
it keeps happening though
Untitled
Yes, it is not possible to read your screenshot. Copy and paste your code below and please format your code when you do so. To format, select the code and hit ctrl+o.
Kf
Size should be in setup, not draw.
You set the size once, at the start, not every frame.