开发者

Java applet game does not work on Macs, even though it does work on PCs

I made a game that is based in a jpanel. When I a开发者_开发技巧dd the jpanel to a jframe, it works fine on both pc's and macs.

here is the class where I add the jpanel to the jframe:

import javax.swing.JFrame;

public class Start{
   public static void main(String[] args){

      JFrame f = new JFrame("Rocks");
      f.setSize(600,500);
      f.setResizable(false);
      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      Board b = new Board();
      f.add(b);
      f.setVisible(true);
   }
}

However, when I add this jpanel to a japplet, it still works perfectly on pc's, but not on macs. In the eclipse applet tester, the first screen paints, but it doesn't accept keyboard input to start the game. In any browser/html page though, the game doesn't seem to load at all, and when I open the java console of chrome I see no errors.

here is the class where I add the jpanel to the japplet

import javax.swing.JApplet;

public class rockAppletStart extends JApplet{

   public void init(){
      Board b;
      b = new Board();
      add(b);
      b.focus();
   }
   public void start(){}
   public void stop(){}
   public void destroy(){}
}

I would appreciate any help that could be offered, and I'm willing to provide more information if necessary. I could even provide the other classes of the game, but there very long and messy, and I'd rather not unless necessary.

The applet version of the game can be found here at gamejolt.com, if you feel like testing it out. If you have a pc, it should work fine, but with a mac it won't.

** edit ** here you can download the .jar file of all the classes and resources. Feel free to use the files to test out your solution yourself if you want... Otherwise, Ill have access to a mac on Tuesday and I will test all solutions then.

http://dl.dropbox.com/u/18832480/Rocks_Source_file.jar


This is just a SWAG, but since Swing threading issues can often cause pernicious, unpredictable and hard to detect errors, what if you create your applet in a thread-safe manner? i.e.,

public void init() {
   try {
      javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
         public void run() {
            createGUI();
         }
      });
   } catch (Exception e) {
      System.err.println("createGUI didn't successfully complete");
   }
}

private void createGUI() {
   Board b;
   b = new Board();
   getContentPane().add(b);
   b.focus()
}


The JApplet is stealing the focus from the Board. To prevent it, add the following to the end of your init() method:

setFocusable(false);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜