Jump to content


Java Applet - Simple Mouse Problem I Don't Understand


5 replies to this topic

#1 Dark Storm

    New Member

  • Members
  • PipPip
  • 20 posts

Posted 05 February 2007 - 11:28 PM

I have a java game I am developing right now and I have it running in a applet form. I handle mouse and keyboard interaction through a basic Controller class that extends KeyAdapter and implements MouseListener, MouseMotionListener. When the game switches states from the Menu to the built in Editor to the Game, it is supposed to remove the Controller and replace it with a new one. So when the user is in the menu, he is using a MenuController object that extends Controller, when he is in the game he uses a GameController object and when he switches from one state to another, the controller changes.

I have the appropriate code,

applet.removeMouseListener(blah); 

applet.removeMouseMotionListener(blah); 

applet.removeKeyListener(blah);

applet.addMouseListener(newBlah);

applet.addMouseMotionListener(newBlah);

applet.addKeyListener(newBlah);


I am writing the game in Eclipse and when I run it as an applet from inside eclipse, it works perfectly, one controller is replaced with another one as the game state changes.

When I create my own html file:

<HTML>

<HEAD><TITLE>Zone Control Game</TITLE></HEAD>

<BODY BGCOLOR=#000000>

<APPLET CODE=game.GameApplet.class WIDTH="400" HEIGHT="300">

</APPLET>

</HTML>


and run it (both in IE and firefox) the controller switching doesn't take place like it should. It just sticks with the first controller I give it, MenuController and doesn't switch.

I know the <applet> tag is suppose deprecated, but I hate messing with object tags. Is this my problem or is there something else I should know about applets?

This doesn't seem to make sense because Eclipse just creates its only own html file, using the applet tag, and runs a mini browser on it and it works fine.

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 4782 posts
  • LocationBellevue, WA

Posted 06 February 2007 - 12:32 AM

Well, take a look at the HTML code that Eclipse generates, and try duplicating that in your own HTML.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 Dark Storm

    New Member

  • Members
  • PipPip
  • 20 posts

Posted 06 February 2007 - 08:07 PM

The code is exactly the same.

I investigated a little further, and running the html page Eclipse generates in IE causes the same result as the html page I wrote.

Only the Eclipse Applet Viewer runs the program as intended.

Is there something I don't know about the <applet> tag or about applets in general?

#4 Reedbeta

    DevMaster Staff

  • Administrators
  • 4782 posts
  • LocationBellevue, WA

Posted 06 February 2007 - 10:50 PM

Maybe Java is not installed properly on your system. If you go to view some Java applet on the Web, for instance this one, does it work? One difference I note is that the page I linked has a 'codebase' attribute in the applet tag giving the server directory that the .class file is located in. Maybe you need to add that attribute to your own code.
reedbeta.com - developer blog, OpenGL demos, and other projects

#5 Dark Storm

    New Member

  • Members
  • PipPip
  • 20 posts

Posted 06 February 2007 - 11:43 PM

I think I may have figured it out. Whenever the program opens the editor or the game, it loads by default a file named standard.map containing the map to edit or play on. The java console is telling me every time I switch that there is a:

Exception in thread "AWT-EventQueue-7" java.security.AccessControlException: access denied (java.io.FilePermission standard.map read)

I have a feeling this is causing my problems. How do I fix this?

#6 Reedbeta

    DevMaster Staff

  • Administrators
  • 4782 posts
  • LocationBellevue, WA

Posted 07 February 2007 - 02:11 AM

You're reading a file from the local hard drive? Well then I'm not surprised! Applets in a web browser run sandboxed and aren't allowed to read local files. (Can you imagine what a security risk that would be?) You might have more success putting the file and applet on a local webserver and seeing if you can read the file through HTTP, though I'm not sure if this is allowed either.
reedbeta.com - developer blog, OpenGL demos, and other projects





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users