我使用Processing IDE創建了一個應用程序,該應用程序允許用戶在HTML草圖上繪製。使用html觀看java按鈕點擊
現在,應用程序是這樣的:
所以,當我點擊「新素描」,它會創建一個新的sketch.html
文件的文件夾中。現在,我想通過點擊「餡餅」按鈕創建一個餅圖,它看起來像這樣:
所以基本上,我的問題是,如何讓HTML聽我的Java自定義按鈕功能? (也許通過JSP,但我不知道)
Button類的樣子:
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頁面知道我的按鈕已被點擊並執行以下操作。任何有用的建議將非常有幫助!
謝謝凱文!因此,爲了創建文件,我使用了「新的skecth」按鈕。每次點擊時,它都會自動在sketch文件夾中創建帶「.html」和「.js」擴展名的文件。 – duststar0213