public class One extends View{
private static final float RADIUS = 30;
private Paint backgroundPaint;
private Paint myPaint1;
private Paint myPaint2;
private Paint myPaint7;
private Paint myPaint8;
private Paint myPaint9;
public One(Context context, AttributeSet attrs){
super(context, attrs);
backgroundPaint = new Paint();
backgroundPaint.setColor(Color.YELLOW);
myPaint1 = new Paint();
myPaint2 = new Paint();
myPaint7 = new Paint();
myPaint8 = new Paint();
myPaint9 = new Paint();
myPaint1.setColor(Color.BLUE);
myPaint2.setColor(Color.BLUE);
myPaint7.setColor(Color.BLUE);
myPaint8.setColor(Color.BLUE);
myPaint9.setColor(Color.BLUE);
}
@Override
public boolean onTouchEvent(MotionEvent event){
int action = event.getAction();
switch(action){
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE:
final float a = event.getX();
final float b = event.getY();
if(Math.sqrt(Math.pow(a - 160, 2) + Math.pow(b - 100, 2)) <= RADIUS){
myPaint1.setColor(Color.RED);
}
else if(Math.sqrt(Math.pow(a - 160, 2) + Math.pow(b - 140, 2)) <= RADIUS){
myPaint2.setColor(Color.RED);
}
if(Math.sqrt(Math.pow(a - 100, 2) + Math.pow(b - 140, 2)) <= RADIUS){
myPaint7.setColor(Color.RED);
}
else if(Math.sqrt(Math.pow(a - 120, 2) + Math.pow(b - 160, 2)) <= RADIUS){
myPaint8.setColor(Color.RED);
}
else if(Math.sqrt(Math.pow(a - 140, 2) + Math.pow(b - 180, 2)) <= RADIUS){
myPaint9.setColor(Color.RED);
}
return true;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
break;
}
return(true);
}
@Override
public void onDraw(Canvas canvas){
int width = canvas.getWidth();
int height = canvas.getHeight();
switch(){
Case Eng.A
canvas.drawRect(0, 0, width, height, backgroundPaint);
int[] start1 ={160,160};
int[] end1 = {100,120};
Paint[] paint1 = {backgroundPaint, myPaint1, myPaint2};
for (int i=0; i<start1.length; i++) {
canvas.drawCircle(start1[i],end1[i],RADIUS,paint1[i]);
}
break;
Case Eng.B
canvas.drawRect(0, 0, width, height, backgroundPaint);
int[] start2 = {100,120,140,};
int[] end2 = {140,160,180};
Paint[] paint2 = {backgroundPaint, myPaint7, myPaint8, myPaint9};
for (int a=0; a<start2.length; a++) {
canvas.drawCircle(start2[i],end2[i],RADIUS,paint2[i]);
}
break;
}
invalidate();
}
}
}
switch문을 써서 첫번째 케이스 나오고 터치 하면 두번째 케이스 나오고(첫번째케이스는 사라지구요) 하고 싶은데, switch문 주는거랑 터치이벤트를 어떻게 줘야할지 잘 모르겠어요ㅜㅜ
어떻게 써야 좋을지 코드면 댓글로 남겨주시면 열심히 배우겠습니다~