Graphics don't show

Hi,

I hope this is the right place to post it, as I'm not very used to Java.

I'm building an applet where I'm using user controls (non-Swing) and standard graphics functions (java.awt.Graphics). My problem is, the applet viewer of NetBeans shows my applet perfectly fine, but the browsers don't show any graphics, only user controls. I've tried everything and I can't understand what could be the reason. I have another applet which is very similar to the first one and it works fine in both the viewer and the browsers. I've made the imports, implements and .html files of both applets as identical as possible, still nothing.

Any help would be greatly appreciated.

[698 byte] By [keyangena] at [2007-9-23]
# 1
applets in browsers must be embedded in HTML pages- how did you do it?and is Java installed in your brwosers?
must41a at 2007-7-11 > top of java,Security,Cryptography...
# 2

Thanks for the reply.

Yes, as I said, I have one very similar applet which works fine in the browser as well as in the applet viewer. The one I'm having problems with works partly, so Java is installed in both of my browsers (IE and Firefox).

I embedded the applet the easiest way:

<APPLET code="sauna.class" width=600 height=400></APPLET>

(hope it shows)

Maybe there's something very specific in the NetBeans settings that needs to be changed. I know it has to be tiny, otherwise there would be an obvious difference from the working applet. Any ideas? Thanks.

keyangena at 2007-7-11 > top of java,Security,Cryptography...
# 3
In case you're wondering, my applet consists of only one class and thus only one .class file.
keyangena at 2007-7-11 > top of java,Security,Cryptography...
# 4

Haha, solved the problem and it couldn't get more ridiculous.

I started some thorough debugging (couldn't use IDE debugger as I had no problems in the IDE) and suddenly found out that the browser simply wouldn't let my paint() method finish executing and thus wouldn't display the contents of the backbuffer. So, by inserting some code the execution of which I'd definitely see, I searched for the exact place of the problem.

So the problem was that instead of

gBuffer.setColor(Color.BLACK);

I should have used

gBuffer.setColor(Color.black);

The ***** (Java) wasted half of my day because of a case error. I understand that Java is a case-sensitive language, but why would it then let me use (and even propose the usage of) CAPS name when the browser Java wouldn't actually allow it?

keyangena at 2007-7-11 > top of java,Security,Cryptography...
# 5
well both are OK (look at the Color class in the API docs, youcan use either low case ou upper case) i just don,t see why one is better than the other (?) but still java is slow and buggy in most browsers...
must41a at 2007-7-11 > top of java,Security,Cryptography...
# 6

> The ***** (Java) wasted half of my day because of a case error. I understand that

> Java is a case-sensitive language, but why would it then let me use (and even propose

> the usage of) CAPS name when the browser Java wouldn't actually allow it?

The constant Color.black has always been part of the Color class (since 1.0),

but the style convention is for constants to be in all caps, so constants like Color.BLACK

were introduced in 1.4, see:

http://java.sun.com/j2se/1.3/docs/api/java/awt/Color.html#field_summary

http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Color.html#field_summary

So if this was indeed your problem, the it's a case of developing in one JRE

then deploying to an earlier JRE. Didn't running the applet in your browser cause

an obvious exception and stack trace to be printed in your browser's Java Console Window?

Now I'm too polite, perhaps to a fault, so I'm not going to call anyone or anything

a ***** here. But perhaps you've learned a valuable lesson about switching from a newer

to an older JRE, and in the future you'll either update your prowser's plugin, or

roll back your development evnironment to match your target ennvironment.

DrLaszloJamfa at 2007-7-11 > top of java,Security,Cryptography...
# 7

> but still java is slow and buggy in most browsers...

I'm not an applet supporter, but I don't think you can blame "java"

for all those old microsoft jre's out there. This page has a link

to an amusing applet (as plugged on java.net):

http://www.babynamewizard.com/namevoyager/

DrLaszloJamfa at 2007-7-11 > top of java,Security,Cryptography...
# 8

> I'm not an applet supporter, but I don't think you can blame "java" for all those old microsoft jre's out there.

i never blamed java- it's just that once i tried making an applet an even though i'd installed java correctly in all browsers it behaved differently (and badly) in each of them- browsers often have problems, especially with input

must41a at 2007-7-11 > top of java,Security,Cryptography...