File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ActionListener and paint method

 
Abeer El-shaer
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic