| 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
|
|
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.
|
 |
 |
|
|
subject: program not running
|
|
|