0

Greetings great minds of stackoverflow. I have recently been programming a small 2D game in java, and i wanted to export it into an applet, that can go on a webpage. I did so, and the code ran fine both when run as an applet, and as an application. However, whenever i ran the code as an applet the small, default, applet window would show up, and then another window, with the correct size displaying the contents, would show up afterwards. I think that is the reason it will not display properly on my webpage. I am assuming it is displaying the contents from the first window, the empty one. I am wondering how I can make it so only one window is displayed. I am using Canvas to display my window. I will upload any code requested. thank you in advance!

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433

1 Answers1

1
Java Plug-in 10.5.1.255
Using JRE version 1.7.0_11-b21 Java HotSpot(TM) Client VM
User home directory = C:\Users\Andrew
----------------------------------------------------
c:   clear console window
..
0-5: set trace level to <n>
----------------------------------------------------
Attempting to start init...
-INIT METHOD STARTED-
Preferred size set to java.awt.Dimension[width=852,height=480]
Initialized JFrame with size java.awt.Dimension[width=852,height=480]
Initialized screen (284x160)
Initialized keyboard
Added key listener
Resizeable set to false
Title set
Game component added to screen
Frame packed
Exception in thread "AWT-EventQueue-3" java.lang.NullPointerException
    at sun.awt.SunToolkit.createImage(Unknown Source)
    at com.sun.deploy.uitoolkit.impl.awt.AWTErrorPanel.getErrorImage(Unknown Source)
    at com.sun.deploy.uitoolkit.impl.awt.AWTErrorPanel.paintComponent(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JComponent.paintToOffscreen(Unknown Source)
    at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
    at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
    at javax.swing.RepaintManager.paint(Unknown Source)
    at javax.swing.JComponent._paintImmediately(Unknown Source)
    at javax.swing.JComponent.paintImmediately(Unknown Source)
    at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
    at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
    at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
    at javax.swing.RepaintManager.access$700(Unknown Source)
    at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

I.E. No applet, no window. Output from console set to trace level 5.

Update

New results:

// ..
Frame packed
java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "exitVM.0")
    at java.security.AccessControlContext.checkPermission(Unknown Source)
    at java.security.AccessController.checkPermission(Unknown Source)

Does the code (lacking an SSCCE we can only guess), call at any time..

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

?

If so, change it to:

// See http://stackoverflow.com/a/7143398/418556 for demo.
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

The latter will be allowed in a sand-boxed applet, whereas EXIT_ON_CLOSE is not permitted even in a trusted applet.

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433