• Post Reply Bookmark Topic Watch Topic
  • New Topic

Display and change color in Swing  RSS feed

 
Khaled Sherif
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trying to learn a GUI example using swing. If someone is aware, I am following the example in book Head First Java, Chapter 12 P. 371. The book, however, used Java 5 and I am on 8 and noticed some method names are changed already. Now my 2 classes compile successfully, but when I run them, I don't see the oval shape drawn on the frame. That is what MyDrawPanel class should do and then upon each press on the mouse the color of the circle should change randomly. I see the mouse and can click but of course nothing is happening. Attached are the source for the 2 classes, can someone tell me what I am doing wrong here.

Here is the MyDrawPanel class

and here is the SimpleGui3C class
 
Norm Radder
Rancher
Posts: 1733
22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure you are overriding the correct paint method. Is paintAll called after a call to repaint?
 
Rob Camick
Ranch Hand
Posts: 2756
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't override paintAll().

Custom painting is done by overriding paintComponent().

Read the section from the Swing tutorial on Custom Painting for more information and working examples.
 
Fred Kleinschmidt
Bartender
Posts: 507
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This construct of add() is obsolete; you should use instead.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!