Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How can I call drawOval as an action listener?

843806May 3 2009 — edited May 15 2009
Hey all,
I am trying to use a button to trigger an animation on a JPanel. For starters, I want to draw a circle, but when I fire the event, the new circle is not displayed. Here is a toy clone:
JButton button = new JButton("GO");
button.addActionListener(new ActionListener() {
     public void actionPerformed(ActionEvent ae) {
         runFoo();
     }
});

public void runFoo() {
     repaint();
}

public void paintComponent(Graphics g) {
     super.paintComponent(g);
     g.setColor(Color.BLACK);
     g.drawOval(myX, myY, 50,50);
}
Thank you all,
Rob Kallman
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 12 2009
Added on May 3 2009
7 comments
720 views