我建議您在processing.org上查看Buttons tutorial。以下代碼是本教程中所包含內容的子集(但是,您需要查看本教程中的所有代碼)。評論是我的。
void setup() {
// Create instances of your button(s)
}
void draw() {
// Draw buttons, update cursor position, check if buttons have been clicked.
}
// Provides the overRect() method (among others).
class Button
{
// If the cursor is placed within the footprint of the button, return true.
boolean overRect(int x, int y, int width, int height)
{
if (mouseX >= x && mouseX <= x+width && mouseY >= y && mouseY <= y+height) {
return true;
}
else {
return false;
}
}
}
class RectButton extends Button
{
// Create a rectangle button with these size/color attributes.
RectButton(int ix, int iy, int isize, color icolor, color ihighlight)
{
x = ix;
y = iy;
size = isize;
basecolor = icolor;
highlightcolor = ihighlight;
currentcolor = basecolor;
}
// Determines whether the cursor is over the button.
boolean over()
{
if(overRect(x, y, size, size)) {
over = true;
return true;
}
else {
over = false;
return false;
}
}
// Draws the rectangle button into your sketch.
void display()
{
stroke(255);
fill(currentcolor);
rect(x, y, size, size);
}
}
這是什麼語言? Java的? – jli 2012-02-29 22:37:41
@jli http://processing.org/ – gary 2012-03-01 01:11:05