Can someone provide me an example on how to extend a java class in java script using Rhino's java adapter ?
解决方案
For anyone else who might come across this, there's a decent example here (the author uses it to extend awt.Canvas).
var smileyCanvas = new JavaAdapter(awt.Canvas, {
paint: function (g) {
var size = this.getSize();
var d = Math.min(size.width, size.height);
var ed = d / 20;
var x = (size.width - d) / 2;
var y = (size.height - d) / 2;
// draw head (color already set to foreground)
g.fillOval(x, y, d, d);
g.setColor(awt.Color.black);
g.drawOval(x, y, d, d);
// draw eyes
g.fillOval(x+d/3-(ed/2), y+d/3-(ed/2), ed, ed);
g.fillOval(x+(2*(d/3))-(ed/2), y+d/3-(ed/2), ed, ed);
//draw mouth
g.drawArc(x+d/4, y+2*(d/5), d/2, d/3, 0, -180);
}
});
There's more information on MDN, including a brief explanation and calling syntax example.