0

I am starting Java and found this interesting.

In Java AWT when we create a button then we use an ActionListener and then we write a paint() function.

But when we create a checkbox then we use an ItemListener and in the paint() function we use repaint() and then we write repaint(). Why do we use repaint()? Why do we not use repaint() in case of an ActionListener?

Yassin Hajaj
  • 21,337
  • 9
  • 51
  • 89
David
  • 4,266
  • 8
  • 34
  • 69
  • http://stackoverflow.com/questions/10768619/paint-and-repaint-in-java – eldo Jun 16 '16 at 11:49
  • Yes, I read this. My specific question is why we use only in Itemlistener not in Actionlistener. – David Jun 16 '16 at 11:53
  • "public void repaint() Repaints this component. If this component is a lightweight component, this method causes a call to this component's paint method as soon as possible. Otherwise, this method causes a call to this component's update method as soon as possible." javadoc. You should understand first what they do, and you will be able to use them properly. – eldo Jun 16 '16 at 12:04
  • Thanks eldo. I will do some more practice to understand better. Thanks a ton again. – David Jun 16 '16 at 12:06
  • Your question makes no sense. Who is that “we” that does the things you describe? There is no such rule regarding listeners and `paint()`/`repaint()` methods. If you are referring to a particular code, provide the reference. – Holger Jun 16 '16 at 12:32

0 Answers0