aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes ActionListener and paint method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "ActionListener and paint method " Watch "ActionListener and paint method " New topic
Author

ActionListener and paint method

Abeer El-shaer
Greenhorn

Joined: Nov 01, 2012
Posts: 29

i have tried allcode that would make the program to enter the number of balls will be drawn then paint it but the paint method always is executed befor the button command and when i but the paint method in the action listener still i have a lot of errors so pleaze help!
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10451
    
    8

1) Override paintComponent() and not paint()
2) for(int i=0;i<3;i++) Define an instance variable, something like numBalls and use instead of 3.
3) In your actionPerformed take the user input, parse it to an int and assign it to numBalls. Then invoke repaint()
4) The call to repaint() from inside your paint() doesn't make sense. Take it out

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39409
    
  28
The call to setVisible should come last.
Please don't use green writing; it is difficult to read and I have changed it to black.
Abeer El-shaer
Greenhorn

Joined: Nov 01, 2012
Posts: 29
Maneesh Godbole wrote:1) Override paintComponent() and not paint()
2) for(int i=0;i<3;i++) Define an instance variable, something like numBalls and use instead of 3.
3) In your actionPerformed take the user input, parse it to an int and assign it to numBalls. Then invoke repaint()
4) The call to repaint() from inside your paint() doesn't make sense. Take it out

thanks a lot i got it
it's executable now
 
 
subject: ActionListener and paint method