🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: netscape.devs-java
Article #1

Re: Netscape 6.1 frame problem

#1
From: Tony Swain
Date: Sun, 09 Jun 2002 02:33
129 lines
4053 bytes

Dan Marcus wrote:

   <SNIP>

Hi Dan,
I changed and tested this and it works.

//-------------  <FIXED_HTML> ------------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<HTML>
  <HEAD>
    <TITLE>This should show a frame</TITLE>
  </HEAD>
  <BODY>
  <APPLET width="200" height="100" code="AppletWithFrame" ></APPLET>
  </BODY>
</HTML>

//----------- </FIXED_HTML>

   My methods are unconventional insofar as
every Java book/example I have ever seen, but
they are derived over many years and solve many
issues of many Java versions.
That is they were not construed in a vacuum...
   (And they generally work) Hmm touch wood :)

     There are several rules I ues.

#1 ALWAYS imlement the Runnable interface
     This leads to the next statement.
#2 ALWAYS overwirte start() stop() l(ike in this example)
     This works around many issues pertianing to Threads
across different JVMS and versions.

# ALWAYS synchronized on start() stop() and init()
this FORCES serialization of the whole initialization
process and avoids several pitfalls such as your frame
being access before it is in fact initialized.
The "boolean initialized"  is there to work
around an issue of the older browsers calling
start()/stop()/init() multiple times in rapid succession.
It also allows you to retain the Applet context if the
user leaves the page and comes back under
pre 1.3.1 JVMs.  The lastest versions destroy
everything when you leave the page.


//---------------- Working APPLET

import java.awt.*;

public class AppletWithFrame extends java.applet.Applet implements Runnable{
Thread task = null;
boolean initialized = false;  // This works around
Frame frame  = null;          // multiple initialization issues.
int iteration = 0;

public synchronized void start()
{
   task = new Thread(this);
   task.start();
}

public synchronized void stop()
{
   task = null;
}

public synchronized void init () {
   if(initialized)
      return;
   add(new Label("Here is a label to show it's loaded."));
   frame  = new Frame("Frame's up");
   frame.add(new Label("Here's a frame label"));
   frame.pack();
   frame.show();
   initialized = true;
}

public synchronized void run()
{
Thread controlThread = Thread.currentThread();
   while(controlThread == task)
   {
      try{
          wait(1000);
      }
      catch(InterruptedException ie)
      {
      }
      getAppletContext().showStatus("Running "+iteration++);
   }
}
     // Mr. Kok's solution to the window freeze bug
     // under the old 1.1.5 JVM
     // Basically wase some time to allow
     // for post processing.
     // Does not apply to newer JVMs.

public synchronized void destroy()
{
   try
   {
      wait(1000);
   }
   catch(InterruptedException ie)
   {
   }
}

}

//------------------------------

   This should work for you.
Goood Luck!
Sincerely:

--
Tony Swain
Senior V.P. of Software Development Hyperbyte inc.
http://www.hyperbyte.ab.ca
Netscape DevEdge Champion Devs-Java Newsgroup
snews://secnews.netscape.com/netscape.devs-java
Technical Details
Message-ID: <3D02BE78.BD20539A@hyperbyte.ab.ca>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-netscape.public.mozilla.java.mbox.zip!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeed.netscape.com!secnews.netscape.com!not-for-mail
References: <adm455$qse$1@newsreader.wustl.edu>

Show Full Headers
Complete Article Headers
Message-ID: <3D02BE78.BD20539A@hyperbyte.ab.ca>
Subject: Re: Netscape 6.1 frame problem
Date: Sat, 08 Jun 2002 20:33:28 -0600
From: Tony Swain <tony@hyperbyte.ab.ca>
References: <adm455$qse$1@newsreader.wustl.edu>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-netscape.public.mozilla.java.mbox.zip!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeed.netscape.com!secnews.netscape.com!not-for-mail
Newsgroups: netscape.public.mozilla.java,netscape.devs-java
Organization: What's that?
Lines: 131
NNTP-Posting-Host: 216.123.213.218
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Mozilla 4.78 [en] (Win98; U)
X-Accept-Language: en