• 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
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

program not running

 
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
 
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
 
Bartender
Posts: 3648
16
Mac OS X Firefox Browser 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:


 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • 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.
 
    Bookmark Topic Watch Topic
  • New Topic