/ Forside / Teknologi / Udvikling / Java / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
Java
#NavnPoint
molokyle 3688
Klaudi 855
strarup 740
Forvirret 660
gøgeungen 500
Teil 373
Stouenberg 360
vnc 360
pmbruun 341
10  mccracken 320
[eng] Need help with an applet (110 line a~
Fra : Martin Schou


Dato : 11-02-02 15:01

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



 
 
J N (11-02-2002)
Kommentar
Fra : J N


Dato : 11-02-02 18:24

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
>
>
>



J N (11-02-2002)
Kommentar
Fra : J N


Dato : 11-02-02 18:25

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
>
>
>



Martin Schou (12-02-2002)
Kommentar
Fra : Martin Schou


Dato : 12-02-02 11:00

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

Browsers refuse to load the applet, it crashes with no error messages. I
tried sacrificing a chicken and a goat while dancing the sacred dance, but
neither Opera nor Internet Explorer wanted to tell me, why the applet
crashed.

It simply doesn't work.

> Post a link that will run the applet

That would be of little use, since I don't have access to a public server,
where I can place the applet. If, by some magic mumbo jumbo, you can gain
access to my private network without breaking various laws, the applet is
running at
http://192.168.1.39/Applet_That_Will_Not_Work_No_Matter_What_I_Try_Which_Is_
Why_I_Need_Your_Help.html
but I doubt that is of much use.

//Martin Schou



Ingo Pakleppa (12-02-2002)
Kommentar
Fra : Ingo Pakleppa


Dato : 12-02-02 11:18

You may already have tried that, but maybe it helps if you go to the
Control Panel, open the Java Plug-in settings, and enable Show Java
Console and Show Exception Dialog Box. IE would probably ignore this
and use its own JVM, but Opera should honor the settings you changed.
I think.

Ingo

On Tue, 12 Feb 2002 10:59:38 +0100, "Martin Schou"
<martin.schou@grue-hornstrup.dk> wrote:

>> What is the problem, except that "its doesn't work"?
>
>Browsers refuse to load the applet, it crashes with no error messages. I
>tried sacrificing a chicken and a goat while dancing the sacred dance, but
>neither Opera nor Internet Explorer wanted to tell me, why the applet
>crashed.
>
>It simply doesn't work.
>
>> Post a link that will run the applet
>
>That would be of little use, since I don't have access to a public server,
>where I can place the applet. If, by some magic mumbo jumbo, you can gain
>access to my private network without breaking various laws, the applet is
>running at
>http://192.168.1.39/Applet_That_Will_Not_Work_No_Matter_What_I_Try_Which_Is_
>Why_I_Need_Your_Help.html
>but I doubt that is of much use.
>
>//Martin Schou
>
>

Seeking a JAVA opportunity in San Diego

Martin Schou (12-02-2002)
Kommentar
Fra : Martin Schou


Dato : 12-02-02 13:00


"Ingo Pakleppa" <ipakleppa@cox.net> wrote in message
news:3c68eb59.5384371@news.west.cox.net...
> You may already have tried that, but maybe it helps if you go to the
> Control Panel, open the Java Plug-in settings, and enable Show Java
> Console and Show Exception Dialog Box. IE would probably ignore this
> and use its own JVM, but Opera should honor the settings you changed.
> I think.

Hmm ... can't get Opera to show the console ... anyways, I got the applet
working in Opera.
javac -target 1.1 appletname.java
helped with that (thank you Lasse Westh-Nielsen)

Now I can't get it running in Internet Explorer. The Console in Explorer
says the following:

java.lang.ClassNotFoundException: java.security.AccessControlException
at com/ms/vm/loader/URLClassLoader.loadClass
at java/lang/ClassLoader.loadClassInternal
at Empty_2.init
at com/ms/applet/AppletPanel.securedCall0
at com/ms/applet/AppletPanel.securedCall
at com/ms/applet/AppletPanel.processSentEvent
at com/ms/applet/AppletPanel.processSentEvent
at com/ms/applet/AppletPanel.run
at java/lang/Thread.run
I don't use java.security.AccessControlException, or anything from the
java.security package, so I guess it's something that is automatically
loaded - but not supported by Internet Explorer? Any ideas as to how to
solve that problem?

Martin Schou



J N (12-02-2002)
Kommentar
Fra : J N


Dato : 12-02-02 22:54

Martin Schou wrote:
> "Ingo Pakleppa" <ipakleppa@cox.net> wrote in message
> news:3c68eb59.5384371@news.west.cox.net...
>
>>You may already have tried that, but maybe it helps if you go to the
>>Control Panel, open the Java Plug-in settings, and enable Show Java
>>Console and Show Exception Dialog Box. IE would probably ignore this
>>and use its own JVM, but Opera should honor the settings you changed.
>>I think.
>>
>
> Hmm ... can't get Opera to show the console ... anyways, I got the applet
> working in Opera.
> javac -target 1.1 appletname.java
> helped with that (thank you Lasse Westh-Nielsen)
>
> Now I can't get it running in Internet Explorer. The Console in Explorer
> says the following:
>
> java.lang.ClassNotFoundException: java.security.AccessControlException
> at com/ms/vm/loader/URLClassLoader.loadClass
> at java/lang/ClassLoader.loadClassInternal
> at Empty_2.init
> at com/ms/applet/AppletPanel.securedCall0
> at com/ms/applet/AppletPanel.securedCall
> at com/ms/applet/AppletPanel.processSentEvent
> at com/ms/applet/AppletPanel.processSentEvent
> at com/ms/applet/AppletPanel.run
> at java/lang/Thread.run
> I don't use java.security.AccessControlException, or anything from the
> java.security package, so I guess it's something that is automatically
> loaded - but not supported by Internet Explorer? Any ideas as to how to
> solve that problem?
>


Find out where the applet stops. Insert println statements.




Martin Schou (14-02-2002)
Kommentar
Fra : Martin Schou


Dato : 14-02-02 09:38

> Find out where the applet stops. Insert println statements.

If I override the constructor and insert a
"System.out.println("constructor");", it prints out constructor and then
throws the exception. It never reaches init(), which has
"System.out.println("init()"); as the very first line, and I have no idea
what is called after the constructor.

//Martin Schou



Ingo Pakleppa (14-02-2002)
Kommentar
Fra : Ingo Pakleppa


Dato : 14-02-02 12:48

On Tue, 12 Feb 2002 12:59:31 +0100, "Martin Schou"
<martin.schou@grue-hornstrup.dk> wrote:

>
>"Ingo Pakleppa" <ipakleppa@cox.net> wrote in message
>news:3c68eb59.5384371@news.west.cox.net...
>> You may already have tried that, but maybe it helps if you go to the
>> Control Panel, open the Java Plug-in settings, and enable Show Java
>> Console and Show Exception Dialog Box. IE would probably ignore this
>> and use its own JVM, but Opera should honor the settings you changed.
>> I think.
>
>Hmm ... can't get Opera to show the console ... anyways, I got the applet
>working in Opera.
>javac -target 1.1 appletname.java
>helped with that (thank you Lasse Westh-Nielsen)
>
>Now I can't get it running in Internet Explorer. The Console in Explorer
>says the following:
>
>java.lang.ClassNotFoundException: java.security.AccessControlException
> at com/ms/vm/loader/URLClassLoader.loadClass
> at java/lang/ClassLoader.loadClassInternal
> at Empty_2.init
> at com/ms/applet/AppletPanel.securedCall0
> at com/ms/applet/AppletPanel.securedCall
> at com/ms/applet/AppletPanel.processSentEvent
> at com/ms/applet/AppletPanel.processSentEvent
> at com/ms/applet/AppletPanel.run
> at java/lang/Thread.run
>I don't use java.security.AccessControlException, or anything from the
>java.security package, so I guess it's something that is automatically
>loaded - but not supported by Internet Explorer? Any ideas as to how to
>solve that problem?
>
>Martin Schou

Do other applets work in IE? It looks to me as if the JVM installation
might be messed up.

Seeking a JAVA opportunity in San Diego

Martin Schou (14-02-2002)
Kommentar
Fra : Martin Schou


Dato : 14-02-02 13:09

> Do other applets work in IE? It looks to me as if the JVM installation
> might be messed up.

Well - depending on what Applet it is, it works more or less fine. IE can
run the applets at java.sun.com/somethingorother just fine, so I'm pretty
sure it's my applet, that isn't behaving like it should.

Of course, I haven't programmed any (and I do mean any) applets before, so
I'm probably just doing something like I always do in a regular java
program, that is a big no no in applets.



Ingo Pakleppa (15-02-2002)
Kommentar
Fra : Ingo Pakleppa


Dato : 15-02-02 08:33

On Thu, 14 Feb 2002 13:08:51 +0100, "Martin Schou"
<martin.schou@grue-hornstrup.dk> wrote:

>> Do other applets work in IE? It looks to me as if the JVM installation
>> might be messed up.
>
>Well - depending on what Applet it is, it works more or less fine. IE can
>run the applets at java.sun.com/somethingorother just fine, so I'm pretty
>sure it's my applet, that isn't behaving like it should.
>
>Of course, I haven't programmed any (and I do mean any) applets before, so
>I'm probably just doing something like I always do in a regular java
>program, that is a big no no in applets.

The reason I thought it might be a messed-up IE is twofold: first,
your stack dump said "ClassDefNotFoundException" for a standard Java
class, and second, this apparently happens while trying to throw a
security violation exception. Except that it happens while loading the
init() method, before any of your code is ever executed, so there
should not be a chance for a security violation.

Looking at your stack trace again, I notice something else: it appears
that the method that is called is the wrong init() - in the wrong
class or something like that. It says "Empty_2.init()" where I would
have expected whatever_your_applet_class_name_is.init(). Do you have
an explanation, maybe?

Ingo
Seeking a JAVA opportunity in San Diego

Martin Schou (19-02-2002)
Kommentar
Fra : Martin Schou


Dato : 19-02-02 07:16


"Ingo Pakleppa" <ipakleppa@cox.net> skrev i en meddelelse
news:3c6cb3e2.5566695@news.west.cox.net...
> On Thu, 14 Feb 2002 13:08:51 +0100, "Martin Schou"
> <martin.schou@grue-hornstrup.dk> wrote:
>
> >> Do other applets work in IE? It looks to me as if the JVM installation
> >> might be messed up.
> >
> >Well - depending on what Applet it is, it works more or less fine. IE can
> >run the applets at java.sun.com/somethingorother just fine, so I'm pretty
> >sure it's my applet, that isn't behaving like it should.
> >
> >Of course, I haven't programmed any (and I do mean any) applets before,
so
> >I'm probably just doing something like I always do in a regular java
> >program, that is a big no no in applets.
>
> The reason I thought it might be a messed-up IE is twofold: first,
> your stack dump said "ClassDefNotFoundException" for a standard Java
> class, and second, this apparently happens while trying to throw a
> security violation exception. Except that it happens while loading the
> init() method, before any of your code is ever executed, so there
> should not be a chance for a security violation.
>
> Looking at your stack trace again, I notice something else: it appears
> that the method that is called is the wrong init() - in the wrong
> class or something like that. It says "Empty_2.init()" where I would
> have expected whatever_your_applet_class_name_is.init(). Do you have
> an explanation, maybe?

Well, I should have edited that stacktrace, because the class that I'm
actually working on _is_ called Empty_2 (stange name, don't ask) and not
Applet_That_Will_Not_Work_No_Matter_What_I_Try_Which_Is_Why_I_Need_Your_Help

So Empty_2.init() is the correct call.

I don't know what I did, but somehow I've gotten Internet Explorer to run
the applet ... at least partially. Now it won't show any images, but places
the lables like a good little puppy, but no images. It also runs like it
should, but alas, no images, and I have absolutely no idea why. And just to
make it even stranger, the applet works perfectly in Opera, but of course
Opera also runs java through the installed JRE from Sun, which might explain
something

//Martin Schou



Thorbjørn Ravn Ander~ (12-02-2002)
Kommentar
Fra : Thorbjørn Ravn Ander~


Dato : 12-02-02 11:39

"Martin Schou" <martin.schou@grue-hornstrup.dk> writes:

> Browsers refuse to load the applet, it crashes with no error messages. I
> tried sacrificing a chicken and a goat while dancing the sacred dance, but
> neither Opera nor Internet Explorer wanted to tell me, why the applet
> crashed.

Try enabling Java Log in IE before accessing the HTML page
--
Thorbjørn Ravn Andersen
http://unixsnedkeren.dk

Søg
Reklame
Statistik
Spørgsmål : 177552
Tips : 31968
Nyheder : 719565
Indlæg : 6408847
Brugere : 218887

Månedens bedste
Årets bedste
Sidste års bedste