This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Grokking Bitcoin and have Kalle Rosenbaum on-line!
See this thread for details.
Win a copy of Grokking Bitcoin this week in the Cloud/Virtualization forum!
  • 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
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

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: 64131
215
  • 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: 3182
119
  • 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: 3033
22
  • 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: 700
10
  • 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.
 
Destroy anything that stands in your way. Except this tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!