Painting via JButton Events

I am using Swing to create Jbuttons on a JPanel. My aim is for a button to be clicked which responds by painting a graphic (eg a rectangle) on a JPanel.

When I add a ActionListener() to a button and define the actionPerformed() for it, how do I call the following so that it draws the rectangle on the panel?

public void paint (Graphics g) {

g.setColor(blue);

g.drawRect(25, 110, 150, 80);}

Simple problem I guess...Thanks for the help...

[490 byte] By [johrik] at [2007-9-26 2:44:13]
# 1
try repaint inside action performed, if it is not working try paint(panel.getGraphics())
b_babu at 2007-6-29 10:24:07 > top of Java-index,Archived Forums,Swing...