Tuesday, September 07, 2010
 Forum
Minimize
 
  Itellu  Modules  jQuery.CodeHigh...  Java Code Example
Previous Previous
 
Next Next
New Post 11/25/2008 1:36 PM
User is offline ljjhost
30 posts
No Ranking


Java Code Example 
/* 
extracted from "Reference Objects and Garbage Collection"  
(http://java.sun.com/developer/technicalArticles/ALT/RefObj/index.html) 
*/ 
 
import java.awt.Graphics; 
import java.awt.Image; 
import java.applet.Applet; 
import java.lang.ref.SoftReference; 
 
public class DisplayImage extends Applet { 
 
        SoftReference sr = null; 
 
        public void init() { 
            System.out.println("Initializing"); 
        } 
 
        public void paint(Graphics g) { 
            Image im = ( 
              sr == null) ? null : (Image)( 
              sr.get()); 
            if (im == null) { 
                System.out.println( 
                "Fetching image"); 
                im = getImage(getCodeBase(), 
                   "truck1.gif"); 
                sr = new SoftReference(im); 
           } 
           System.out.println("Painting"); 
           g.drawImage(im, 25, 25, this); 
           im = null;   
        /* Clear the strong reference to the image */ 
        } 
 
        public void start() { 
            System.out.println("Starting"); 
        } 
 
        public void stop() { 
            System.out.println("Stopping"); 
        } 
 
} 

------------------------------------------

Source Code

-----------------------------------------

<pre  class="java">
/*
extracted from "Reference Objects and Garbage Collection" 
(http://java.sun.com/developer/technicalArticles/ALT/RefObj/index.html)
*/
 
import java.awt.Graphics;
import java.awt.Image;
import java.applet.Applet;
import java.lang.ref.SoftReference;
 
public class DisplayImage extends Applet {
 
        SoftReference sr = null;
 
        public void init() {
            System.out.println("Initializing");
        }
 
        public void paint(Graphics g) {
            Image im = (
              sr == null) ? null : (Image)(
              sr.get());
            if (im == null) {
                System.out.println(
                "Fetching image");
                im = getImage(getCodeBase(),
                   "truck1.gif");
                sr = new SoftReference(im);
           }
           System.out.println("Painting");
           g.drawImage(im, 25, 25, this);
           im = null;  
        /* Clear the strong reference to the image */
        }
 
        public void start() {
            System.out.println("Starting");
        }
 
        public void stop() {
            System.out.println("Stopping");
        }
 
}

</pre>


Itellu.net
 
Previous Previous
 
Next Next
  Itellu  Modules  jQuery.CodeHigh...  Java Code Example

 

Welcome to dnn modules zcenter!

 

 Jquery.CodeHighlighter
Minimize
Copyright 2007 by My Website