• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

GUI Frame  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the problem with the "frame.getContentPane.add(BorderLayout.SOUTH, button)" line? The compiler cannot find getContentPane symbol


 
Marshal
Posts: 61774
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to our GUIs forum.

As Carey has hinted, getContentPane is a method, so it must have ().
Why are you using that method at all, when you could use this method instead?
Why are you calling the class by such a vague name?
Why are you making the display class implement action listener? even though you will see that in many books, I don't think it is good object‑orientation.
In line 29: Give that method protected access, not public. Make its first line read super.paintComponent(g); That will remove any old painting before you start your new painting.
 
Master Rancher
Posts: 3003
105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'frame.add(component)' will add the component to the center of the contentpane. If you do this a second time, you will overwrite your first component.
'super.paintComponent(g)' is indeed what you would normally do, but why does it not matter here?
 
Rancher
Posts: 2974
20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't generate random numbers in a painting method.

You can't control when Swing will repaint the component. For example if you resize the frame the component is repainted and you will regenerate the random color.

The Color should be a property of the class and you should invoke a method to generate a new random color.

You would then invoke this method in the constructor of your class to initially set the color.
 
Bartender
Posts: 635
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, you have inverted the order of arguments ot the add() method:
 
Will Abaga
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help guys.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!