File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes program not running Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "program not running" Watch "program not running" New topic
Author

program not running

levi sleight
Greenhorn

Joined: Sep 19, 2012
Posts: 19
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

Joined: Mar 10, 2008
Posts: 1409

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


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
levi sleight
Greenhorn

Joined: Sep 19, 2012
Posts: 19
blah, i knew it was something dumb like that, thanks. its fixed
K. Tsang
Ranch Hand

Joined: Sep 13, 2007
Posts: 1219

Further to Jelle's reply, another way of doing this is directly creating the JFrame as your main window like this:



K. Tsang JavaRanch SCJP5 SCJD/OCM-JD
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4165
    
    3

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.


luck, db
There are no new questions, but there may be new answers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: program not running
 
Similar Threads
Why does this still flicker?
JSlider issue
this animation code does not show o/p
Getting JPanel size
drawCenteredString