I wanna stop my netscape from crashing

This is the same question i had posted with a new name!!

let me explain the problem again..
I am actually running an mpeg file on an applet and on it am writing a number of strings at various positions which vary  from time to time based on some other functions in my code .
The mpeg is decoded and stored as images in a linked list .
The painting of these images is done in an animator thread as in the java tutorial.

.......in the run function
//painted is a boolean
Thread.sleep(50 milliseconds)
//image paintimage image to be painted
paintimage =next_image;

}//end run

update(Graphics g)
//double buffering code
//this has been commented

paint(Graphics g)
update(Graphics g);
Now here the problem began when in the NT environment the applet would crash netscape.On noticing the memory requirements realised that it would keep garbling memory and at an increasing rate as if it forgot to garbage collect.Also the processor usage was 100% and then on removing the create image from the double buffering code voila the memory becam stable and also the processor usage came down to 40% .
fially i guess i isolated the createImage to be the culprit aslo is i use any system.out.println statement the result is the same heavy memory usage and processor.
well there is my case ......
i have tried to do a double buffering on small areas but yet the requirements of memory and processor is taxing ....
so please do help me now...

......regarding hey heys answer well u were right i had detected that on commenting the double bufferingcode  the load would go down considerable so the culprit was the create image
now i have the problem of netscape crashing
i feel it is related to the way i make the applet run
i have the start method
which invokes the frame in the applet class

//Applet class
myframe=new frame(this);

in the frame i create threads to
public class myFrame extends Frame implements  WindowListener,Observer, Runnable{.....}

1)download the mpeg file
3) run the mpeg

it uses a stop  method {where i null all the threads}

in netscape
NETSCAPE caused an invalid page fault in
module JRT3240.DLL at 015f:600c46de.

NETSCAPE caused an invalid page fault in
module MSVCRT.DLL at 015f:7800328d.

what do i do??

Also i neede to know how i could give n\both comments the points
 in parts not that anyones is better or worse or that u care for points but then let me know if that can be done

From: heyhey_
 Date: Monday, February 07 2000 - 12:08AM PST  
1. my suggestion was to create the offscreen buffer once :)

  // create the offscreen buffer and associated Graphics
if (offscreen == null)
  offscreen = createImage(box.width, box.height);
  offgc = offscreen.getGraphics();

2. can you post more code ? I would suggest to create the Frame in different Thread, after some sleep ... add some System.out.println()'s and Thread.sleeps() to track the problem  code.

3. I don't know if you can decrease the points, but you can delete this question and and post two dummy ones (please Copy&Paste this question + comments :)

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jamesb111Author Commented:

here is more code i hope it helps

in the applet class
public class MPEG_Play extends Applet {
public void init()
                  the_frame= new myFrame(this);

       public void start()
            //i dont use any of these now
      public  void stop()
            //i want the thread on so that the mpeg keeps playing


in the frame class
public class myFrame extends Frame implements  WindowListener,Observer,Runnable{

in the animator thread run method


while (AnimatorThread != null)
                  { // Is it me ?
                  repaint(); // sets the flag for "update()" --> "paint()"
                        painted = false;
                    try {  // "sleep()" throws the "InterruptedException"
                             starttime += delay; // compute the destination time
                             // if destination time isn't reached --> sleep
                             Thread.sleep(Math.max(0,starttime - System.currentTimeMillis()));
                          //  Thread.sleep(delay);
                    catch (InterruptedException e) { // must be; otherwise it leads to an error
                              System.out.println("IN RUN METHOD in a exception related to delay ");      
                             break;   // because "sleep()" throws the "InterruptedException"

                  /* "ak_pic" is only incremented if the Web browser  */
                  /* had the opportunity to paint the current image.     */
                  /* ("repaint()" sets only a flag: "Please repaint      */
                  /* occasionally!")                               */

                  //if (painted)             
                              ak_pic = ak_pic.next;
            //      if(threaddieflag==1){break;}
            //      System.runFinalization();
            //      System.gc();
            }//animator thread
}//run ends

in the update method
public void update(Graphics g) {  // overwrites the "update()" - method of Applet

            if (Err.Msg != null) { // error ?
            //Double Buffering Code
                                // offscreeng.fillRect(0,0,o_w, o_h);
//in the run method

void run()

      if (ak_pic == null) return;
            g.drawImage(ak_pic.Picture, 0, 0, this);
            painted = true; // "is painted" --> see "run()"


if this code look untidy well i am sorry .....i could not actually format it here ...
See if any of these options help...

Your doublebuffering code above creates an image the size of the whole applet and then paints over this whole area with the background colour and then again with the actual mpeg image.

With the code I posted previously I metioned about creating a smaller clipped area  just the size of your String. Have you tried this?

The code was intended to create a much smaller area of the screen to repaint using a Rectangle class that just covers the area you need to put the string in.

For example, above it is actually this code that is causing the flicker by clearing the applet to it's background colour:

                                // offscreeng.fillRect(0,0,o_w, o_h);

before reinstating the mpeg image. If you don't do this at all  then the background is the previous mpeg frame, thus no flicker.

All you ned to do is paint the mpeg picture into your graphics object on each refresh and then have a small double buffer for your string. You may even not need this...

What I would try doing is just paint the mpeg image down in your update method. All you need to do here is:

public void update(Graphics g) {

  // need reference to current ak_pic.Picture
  g.drawImage(ak_pic.Picture, 0, 0, this);

  //now draw your string onto the applet


Try it like this and see what it looks like.

if you do this in your run method:

  // need reference to current ak_pic.Picture
  g.drawImage(ak_pic.Picture, 0, 0, this);

then you only need to paint the string in your update by clipping out the area of the applet you want to overwrite and just leaving the previous mpeg fram as it was everywhere else.

To create a small double buffer for the string, just do this:

Graphics offgc;
Image offscreen = null;

public void update(Graphics g) {

  // create a small rectangle just the size of the string
  Rectangle box =
    new Rectangle(stringTopLeft, stringTopRight, stringWidth, stringHeight);

  // create the offscreen double buffer and associated Graphics
  // you can also do this just once if the string size does not change

  // it will only be the size of the Rectangle you specify which
  // will be much smaller than the whole applet
  // you are not worried about redrawing the mpeg frame as
  // that can be done with a
  //   g.drawImage(ak_pic.Picture, 0, 0, this);
  // in your run method, so we leave the rest of the applet as it was
  offscreen = createImage(box.width, box.height);
  offgc = offscreen.getGraphics();

  // clear the exposed area
  offgc.fillRect(0, 0, box.width, box.height);

  // do normal redraw
  offgc.translate(-box.x, -box.y);

  // transfer offscreen to window
  g.drawImage(offscreen, box.x, box.y, this);

  // also remove this if you are creating the buffers just once
  //  and the string size does not change
  offscreen = null;
  offgc = null;

This will show your string text with a block of background colour around it.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jamesb111Author Commented:
Thank You
Sorry i took somuch time i did not access the site lately ...
Thanks  again
Glad to help - haven't been around much myself either...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.