[java] This code works in appletViewer but not browser, please help...

Started by
10 comments, last by nowan 22 years, 11 months ago
The following code which comes from my run() method works fine in appletViewer but not in my IE 5.0 browser. The code is for a simple countdown clock during which you must complete the game. The clock displays but will not countdown when tested in the browser. *********************************************** if(secs>0 && gameStart==1 && gameOver==0) { secs--; // clock countdown } if(secs<=4 && secs > 0 && TimersoundPlayed==0 && gameOver==0) { TimerSound.play(); TimersoundPlayed=1; } if(secs<=0) { gameOver=1; } *********************************************** What do you think is going wrong?
Advertisement
That''s not really enough code, but try compiling with the option -target 1.1 , you might be using some 1.2 code.
Thanks lilspikey, but I''ve tried what you suggested with no success. Any other ideas?

Thanks
So what error does it give?
Well, if I look in the Java console part of the browser I do get the following message but I still get it if I comment out the code I posted and re-compile without it.

java.lang.NoSuchMethodError: java/awt/Component: method getWidth()I not found
at Connections.run
at java/lang/Thread.run
Also, I forgot to mention, if I use HTML converter everything works perfectly but this means that the end user has to download a plug-in I think, which kind of counters the whole point of me using Java for a web-based game.
If you look in the java api documentation, you will see that getWidth() has only been a method of component since java 1.2. Hence under IE 5.5 (which ONLY supports java 1.1) the method does not exist, hence the NoSuchMethodError.


Use getSize().width instead.
Im actually having a similar problemo in my own applet using awt (no swing).

The applet works fine in applet viewer.
when i try it in a browser window, it loads up and displays the background image, but its as if its gone through init() (cos it goes through paint() once), but wont go through run() where the core logic lies (yes i know, i wouldve taken a more OO approach, but the assignments due pretty soon and i pannicked, and now the code looks like straight c), and the applet just sits still doing nothing.

it does handle action events, such as clicking on buttons and checkboxes, while in the browser, BUT it only refreshes to the new stuff added by the action when the window is scrolled down or whatever, when it should repaint in one of the timers that sends a repaint 33 times every second.

My conclusion? the threads (run, and extra timers) arent running...why?

here in castle camelot we eat ham and jam and spam alot!
Maybe the extra thread have thrown exceptions and died. Do you get any error messages in the browsers java console?
Well that''s what is happening with my applet too. It seems to go through run() just the once and that''s it. The applet works fine otherwise and responds to mouse clicks with all the right movements and displays.

This topic is closed to new replies.

Advertisement