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 : // 유래. co.kr/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 클래스에서이 라인에서

봐 : 매주 하나의 버튼이 button1을 클릭 할 경우에만 확인하고 있습니다

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

. 당신은 아마 현재 버튼을 클릭 여부를 확인해야 할이 단축 될 수

if (isClicked() == true) { 

:

if (button1.isClicked()) {