วันอาทิตย์ที่ 22 กันยายน พ.ศ. 2556

Button







void setup() {
  size(200, 200);
  background(255);
  println(a.toString());
  println(b.toString());
  a.Clicked();
  a.Display();
}

Button a = new Button("moowan", 100, 100, 50);
Button b = new Button();

void draw() {
  a.Display();
  b.Display();
}

class Button {
  int k = 0;
  int x;
  int y;
  int s;
  String name;

  Button(String n, int a, int b, int c) {
    this.name = n;
    this.x = a;
    this.y = b;
   this.s = c;
  }

  Button() {
    this.name = "Kananard";
    this.x = 50;
    this.y = 50;
    this.s = 20;
  }

  String toString() {
    String s = this.name;
    return s;
  }

  void Clicked() {
    if ((mousePressed && mouseX >=x && mousePressed && mouseX <=x + s) && (mousePressed && mouseY >= y && mousePressed && mouseY <= y + s)) {
      if (k % 8 == 0) {
        println(this.name);
      }
      k = k + 1;
    }
  }
  void Display() {
    rect(x, y, s, s);
    a.Clicked();
    b.Clicked();
   }
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น