【发布时间】:2017-08-27 08:51:57
【问题描述】:
我使用 Processing IDE 创建了一个允许用户在 HTML 草图上绘图的应用程序。
现在,应用看起来像这样:
所以当我点击“新建草图”时,它会在文件夹中创建一个新的sketch.html 文件。现在,我想通过单击“饼图”按钮创建一个饼图,如下所示:
所以基本上,我的问题是如何让 html 听我的 java 自定义按钮功能? (也许是jsp,但我不确定)
按钮类如下所示:
public class Button {
String label; // button label
float x; // top left corner x position
float y; // top left corner y position
float w; // width of button
float h; // height of button
// constructor
Button(String labelB, float xpos, float ypos, float widthB, float heightB) {
label = labelB;
x = xpos;
y = ypos;
w = widthB;
h = heightB;
}
void Draw() {
fill(218);
stroke(141);
rect(x, y, w, h, 10);
textAlign(CENTER, CENTER);
fill(0);
text(label, x + (w / 2), y + (h / 2));
}
boolean MouseIsOver() {
if (mouseX > x && mouseX < (x + w) && mouseY > y && mouseY < (y + h)) {
return true;
}
return false;
}
}
在处理草图中运行。在草图中,鼠标按下特定按钮的动作由MouseIsOver 定义。我希望我的 HTML 页面知道我的按钮被点击并执行以下操作。任何有用的建议都会非常有帮助!
【问题讨论】:
标签: javascript java html processing p5.js