2017-05-11 2 views
0

このチェックリストのコードは処理中ですので、リスト内のいずれかのボタンをクリックしてそのボタンを黒く塗りつぶしたいと思います。私はその部分を単一のボタンのために働いていますが、クラスに多くのボタンを実装してボタンをクリックするたびに、すべてのボタンが一杯になります。 pushMatrix/popMatrix & pushStyle/popStyleを試してみましたが、そのたびにボタンをクリックすると色が変わることはありません。もし誰かが私にそのことを教えることができれば、それは非常に感謝しています。ここで塗りつぶしの問題を処理する際のチェックリスト

は、ボタンのクラスです:

Button button1 = new Button(50, 50, 20, 20, 255); 
Button button2 = new Button(50, 75, 20, 20, 255); 
Button button3 = new Button(50, 100, 20, 20, 255); 
Button button4 = new Button(50, 125, 20, 20, 255); 

void setup() { 
size(500, 500); 
} 

void draw() { 
background(50); 
button1.display(); 
button2.display(); 
button3.display(); 
button4.display(); 
} 
+0

はあなたが理解しました[あなたの最初の質問](のhttp://のstackoverflow。 com/questions/43897582/creating-a-checklist-in-processing)?もしそうなら、それに答えるか、削除してください。そうでない場合は、質問を含めるように編集してください。 –

答えて

1

pushMatrixpopMatrix()機能のみを翻訳して回転を扱う:

class Button { 
// Other optional attributes could be r, g, and b values for examples 
int xLoc; 
int yLoc; 
int wide; 
int tall; 
int fill; 
boolean checked; 

Button(int x, int y, int w, int h, int f) { 
xLoc = x; 
yLoc = y; 
wide = w; 
tall = h; 
fill = f; 
} 

void display() { 
//fill with blue green and create the rect 
fill(fill); 
if (mousePressed) { 
    if (button1.isClicked() == true) { 
    fill = 0; 
    } 
} 
ellipse(xLoc, yLoc, wide, tall); 
} 

// returns true if the mouse is over the button and false otherwise 
boolean isClicked() { 
if (mouseX > xLoc && mouseX < xLoc + wide) { 
    if (mouseY > yLoc && mouseY < yLoc + tall) { 
    return true; 
    } 
} 
return false; 
} 

boolean isChecked() { 
if (fill == 0) { 
    return true; 
} else { 
    return false; 
} 
} 
} 

そしてここでは、メインのコードです。彼らは塗りつぶしの色を扱わない。あなたのButtonクラスで、この行で

ルック:

if (button1.isClicked() == true) { 

ひとつひとつのボタンがbutton1がクリックされた場合のみチェックしています。おそらくそれは、現在のボタンがクリックされたかどうかをチェックすることにしたい。これに短縮することが可能

if (isClicked() == true) { 

if (button1.isClicked()) { 
関連する問題