• Advertisement

Archived

This topic is now archived and is closed to further replies.

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

This topic is 6080 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
That''s not really enough code, but try compiling with the option -target 1.1 , you might be using some 1.2 code.

Share this post


Link to post
Share on other sites
Thanks lilspikey, but I''ve tried what you suggested with no success. Any other ideas?

Thanks

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
Maybe the extra thread have thrown exceptions and died. Do you get any error messages in the browsers java console?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Well that''s correct! Run is called once!

declare you run like this!


public boolean applet_active = true;
public void run()
{
while(applet_active) do_main_loop();
}

private void do_main_loop()
{
blah blah blah blah.....
rubarb rubarb rubarb.....
}



:-)

Share this post


Link to post
Share on other sites
Well, sometimes it just takes someone to come along and state the hidden obvious Thanks a million Chaoslab, everything now hunky cool!

nowan

Share this post


Link to post
Share on other sites

  • Advertisement