Win a copy of Kotlin for Android App Development this week in the Kotlin 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
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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: 62863
203
  • 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: 3080
108
  • 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: 3000
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: 655
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.
 
Do the next thing next. That’s a pretty good rule. Read the tiny ad, that’s a pretty good rule, too.
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!