I have a canvas and I want to draw a rectangle based on a JButton click.
So in other words
private void jb_drawActionPerformed(ActionEvent evt) {
// draw a rectangle method
}
Basically, how do I encorporate the pain(Graphics g) thingamagic in that method? or should I make the rectangle an object and call a "render" method from that object? If so, can someone link a tut?
private void jb_drawActionPerformed(ActionEvent evt) {
myrectange.render(x,y); // ????
}
paint(Graphics g)yourself, always delegate this to a call torepaint. 1) Callrepaint()in yourjb_drawActionPerformedmethod. 2) OverridepaintComponent(Graphics g)and in that method paint your rectangle. The first call will eventually trigger the second one. Btw, you should always overridepaintComponentand never overridepaint(Graphics g).