Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ActionListener and paint method

 
Abeer El-shaer
Greenhorn
Posts: 29
  • 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: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 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: 48981
60
  • Likes 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
  • 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