🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.java
Article #599

Re: [eng] Need help with an applet (110 line applet included)

#599
From: J N
Date: Mon, 11 Feb 2002 17:24
160 lines
5591 bytes
Martin Schou wrote:
> First off let me apologize for the crossposting and for the english post to
> a danish newsgroup.
> 
> Below is a stripped version of an applet, I've been trying to get to work
> for the last week or so.
> What it's supposed to do:
> 
> Get some images from the net (duh) and place them with pixel-precision.
> 
> I use the method
>     private Image ReadImageFromURL( String image )
> to return the apropriate image (we can't have inapropriate images in a
> decent program), which basically just uses
>     Applet.getImage(URL url, String name)
> to return the image. It forms the URL from the variables
>     String ImageHost, ImageDirectory
> 
> I can get this to work in AppletViewer, but I'll be a cross eyed monkey, if
> it will work in a browser. This is rather unfortunate, as I need this to
> work in a browser. I will gladly sacrifice my oldest child (at this point in
> time) to anyone who can get this to work in a browser; I will up the ante
> with my youngest child (at this point in time), if the same person can tell
> me why my puny attempt doesn't work like it's supposed to.
> 


What is the problem, except that "its doesn't work"?

Post a link that will run the applet.


> 
> /************************ start of applet ************************/
> /******************* beware forced line breaks *******************/
> import java.applet.Applet;
> 
> import java.awt.Graphics;
> import java.awt.Image;
> import java.awt.Label;
> 
> import java.io.InputStream;
> 
> import java.net.URL;
> 
> public class
> Applet_That_Will_Not_Work_No_Matter_What_I_Try_Which_Is_Why_I_Need_Your_Help
> extends Applet implements /*Helpless_Programmer, Annoying_Piece_Of_Shit*/
> Runnable
>   {
>     Thread RunningThread;
>     Image Buffer;
>     Graphics GraphicsBuffer;
> 
>     String ImageHost = "http://";
>     String ImageDirectory = "/img/";
>     Image Background;
> 
>     public void init()
>       {
>         ImageHost +=  getCodeBase().getHost();
>         setSize( 1013, 609 );
>         Buffer = createImage(size().width,size().height);
>         GraphicsBuffer = Buffer.getGraphics();
>         initImages();
>       }
> 
>     public void start()
>       {
>         if (RunningThread == null)
>           {
>             RunningThread = new Thread (this);
>             RunningThread.start();
>           }
>       }
> 
>     public void stop()
>       {
>         if (RunningThread != null)
>           {
>             RunningThread.stop();
>             RunningThread = null;
>           }
>       }
> 
>     public void run()
>       {
>         while(true)
>           {
>             drawImages();
>             repaint();
>             System.out.println("repaint()");
>             Sleep( 5000 );
>           }
>       }
> 
>     private void Sleep( int time )
>       {
>         try
>           {
>             RunningThread.sleep( time );
>           }
>         catch( InterruptedException e )
>           {
>             e = null;
>           }
>       }
> 
>     public void update(Graphics g)
>       {
>         paint(g);
>       }
> 
>     public void paint(Graphics g)
>       {
>         g.drawImage (Buffer,0,0, this);
>       }
> 
>     private Image ReadImageFromURL( String image )
>       {
>         try
>           {
>             return getImage( new URL( ImageHost ), ImageDirectory + image );
>           }
>         catch( Exception e )
>           {
>             e.printStackTrace();
>             e = null;
>           }
> 
>         return null;
>       }
> 
>     private void drawImage( Image ImageToManipulate, int x_coords, int
> y_coords, int width, int height )
>       {
>         GraphicsBuffer.drawImage(ImageToManipulate, x_coords, y_coords,
> width, height, null);
>       }
> 
>     private void drawImages()
>       {
>         drawImage( Background,               0, 0, 1013, 609 );
>       }
> 
>     private void initImages()
>       {
>         Background       = ReadImageFromURL( "ventilationsanlaeg.png" );
>       }
>   }
> /************************* end of applet *************************/
> 
> And in case you're wondering, no - I don't have any children, which is why
> I'm willing to sacrifice them only at this point in time.
> 
> Sincerely and frustrated
> Martin Schou
> 
> 
> 
Technical Details
Message-ID: <3C67FE4B.608@no-spam-anneli.dk>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!news.tele.dk!small.news.tele.dk!193.162.153.118!news.tele.dk!not-for-mail
References: <d8Q98.5695$5L3.330766@news010.worldonline.dk>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f9a23,7344a4814c81e894
X-Google-Attributes: gidf9a23,public
X-Google-Thread: f5d71,7344a4814c81e894
X-Google-Attributes: gidf5d71,public
X-Google-ArrivalTime: 2002-02-11 09:24:29 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!news.tele.dk!small.news.tele.dk!193.162.153.118!news.tele.dk!not-for-mail
Message-ID: <3C67FE4B.608@no-spam-anneli.dk>
Date: Mon, 11 Feb 2002 18:24:27 +0100
From: J N <nospam-jnp@no-spam-anneli.dk>
User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US; rv:0.9.8) Gecko/20020205
X-Accept-Language: en-us
MIME-Version: 1.0
Newsgroups: comp.lang.java,dk.edb.programmering.java
To: Martin Schou <martin.schou@grue-hornstrup.dk>
Subject: Re: [eng] Need help with an applet (110 line applet included)
References: <d8Q98.5695$5L3.330766@news010.worldonline.dk>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 162
Organization: TDC Internet
NNTP-Posting-Host: 62.242.16.235
X-Trace: 1013448268 dread04.news.tele.dk 250 62.242.16.235
X-Complaints-To: abuse@post.tele.dk