This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

program not running

 
levi sleight
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so i made a program that just puts a couple of shapes on the screen which i this:





so after that i made a new classs to run it which is here:






but it gave me ab error when i tried to run it which is this:

Exception in thread "main" java.lang.IllegalArgumentException: adding a window to a container
at java.awt.Container.checkNotAWindow(Unknown Source)
at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at javax.swing.JFrame.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at grape2run.main(grape2run.java:9)


i really have no idea what to do. oh also im using eclipse, one of the newest versions
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're adding a JFrame, an instance of grape2, to another JFrame, referenced by variable f in grape2run.
That's not allowed. Try making grape2 a subclass of JPanel instead.

Also I'm moving this to our Swing / AWT / SWT forum for you
 
levi sleight
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
blah, i knew it was something dumb like that, thanks. its fixed
 
K. Tsang
Bartender
Posts: 3457
14
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Further to Jelle's reply, another way of doing this is directly creating the JFrame as your main window like this:


 
Darryl Burke
Bartender
Posts: 5132
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:Further to Jelle's reply, another way of doing this is directly creating the JFrame as your main window like this:

But respect Swing's single threaded rule. All Swing component constructors and methods should be invoked on the EDT, barring the very few that are still documented as being thread safe in the JDK7 documentation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic