Article View: comp.lang.java
Article #598[eng] Need help with an applet (110 line applet included)
From: Martin Schou
Date: Mon, 11 Feb 2002 14:00
Date: Mon, 11 Feb 2002 14:00
149 lines
5151 bytes
5151 bytes
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.
/************************ 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:
<d8Q98.5695$5L3.330766@news010.worldonline.dk>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!news.tele.dk!small.news.tele.dk!212.54.64.131!news100.image.dk!news010.worldonline.dk.POSTED!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f9a23,7344a4814c81e894,start X-Google-Attributes: gidf9a23,public X-Google-Thread: f5d71,7344a4814c81e894,start X-Google-Attributes: gidf5d71,public X-Google-ArrivalTime: 2002-02-11 06:00:43 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!news.tele.dk!small.news.tele.dk!212.54.64.131!news100.image.dk!news010.worldonline.dk.POSTED!not-for-mail From: "Martin Schou" <martin.schou@grue-hornstrup.dk> Newsgroups: comp.lang.java,dk.edb.programmering.java Subject: [eng] Need help with an applet (110 line applet included) Lines: 151 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300 Message-ID: <d8Q98.5695$5L3.330766@news010.worldonline.dk> Date: Mon, 11 Feb 2002 15:00:41 +0100 NNTP-Posting-Host: 213.237.39.12 X-Complaints-To: news-abuse@wol.dk X-Trace: news010.worldonline.dk 1013436041 213.237.39.12 (Mon, 11 Feb 2002 15:00:41 MET) NNTP-Posting-Date: Mon, 11 Feb 2002 15:00:41 MET Organization: Customer of Tiscali A/S (World Online)