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); // ????
}
paintComponent(...)
method (see below). ArrayList<Rectangle>
add to it in your ActionListener, call repaint()
and have the paintComponent(...)
method iterate through the List, drawing rectangles held by it.paintComponent(...)
method is never called directly but rather you suggest to the JVM that it call it by calling repaint()
.paintComponent(Graphics g)
parameter.