IllegalArgumentException: adding a window to a container
I have made a JFrame called PlayWindow (Class file- PlayWindow)
This has got a main with some Frame functionality and its got a second panel class inside called ButtonPanel (Class file- PlayWindow)
This file i can run seperated from the rest.
In this window with the ButtonPanel i want to add a PlayGround panel called PlayPanel (Class file - PlayPanel)
In the StartHandler (Class file - StartHandler) i start this as follows:
Code:
PlayWindow form = new PlayWindow(new PlayPanel(game.getPlayground(), 30, 30, 20, 20));
This doesn't seem to work, i get an IlligalArgumentException.
Seperated from eachother it does work. The Playground functionallity does work with this code
Code:
PlayPanel panel = new PlayPanel(spel.getPlayground(), 30, 30, 20, 20);
I get the following error:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: adding a window to a container
at java.awt.Container.checkNotAWindow(Container.java: 431)
at java.awt.Container.addImpl(Container.java:1039)
at javax.swing.JLayeredPane.addImpl(JLayeredPane.java :212)
at java.awt.Container.add(Container.java:927)
at javax.swing.JRootPane.setContentPane(JRootPane.jav a:608)
at javax.swing.JFrame.setContentPane(JFrame.java:671)
at controller.StartHandler.startGame(StartHandler.jav a:67)
at view.Paneel$StartButtonHandler.actionPerformed(Sta rtForm.java:169)
at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.jav a:6267)
at javax.swing.JComponent.processMouseEvent(JComponen t.java:3267)
at java.awt.Component.processEvent(Component.java:603 2)
at java.awt.Container.processEvent(Container.java:204 1)
at java.awt.Component.dispatchEventImpl(Component.jav a:4630)
at java.awt.Container.dispatchEventImpl(Container.jav a:2099)
at java.awt.Component.dispatchEvent(Component.java:44 60)
at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4577)
at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4168)
at java.awt.Container.dispatchEventImpl(Container.jav a:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478 )
at java.awt.Component.dispatchEvent(Component.java:44 60)
at java.awt.EventQueue.dispatchEvent(EventQueue.java: 599)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122)
BUILD SUCCESSFUL (total time: 4 seconds)