appletviewer and browser,

hello,

I am doing a project that related to web counter by using Java Applet. The problem that I am facing is :

when I use the "drawstring" to display the count number, it doesn't appear in the IE 5.5 browser. But did it when appletviewer. Then i found out that "drawString" cannot be use after the try { }.

I use the try { } when to read and write a file. At first, I read the file and update the count number and write to the file. After all, I want to display the count number on the browser.

How I gotta to display the result? Is it a problem by using the "drawString" while using try { } too?

Beside "drawString", what kind of command can I use?

Is it the version of IE that I am using cannot support Applet? But it can display other Applet.

Thank you for your help.

[842 byte] By [niliep] at [2007-9-26 4:37:07]
# 1
1) Why do you read/write a file in the paint method?2) How do you write a file in the applet? Not everyone can do that, you know...3) You wouldn't happen to get any exceptions, would you? If the code is in a try block, don't you catch anything?
jsalonen at 2007-6-29 17:55:42 > top of Java-index,Archived Forums,Java Programming...
# 2

1 ) ok. Now I am doing a project that use the Java Applet to do a web counter ( you are the visitor of ... ). Then of course I need a file to store the increasing counter ( for example the file contain number 4, while the Applet loaded, the file will be read and the number will be increased to 5 and the 5 will be store to the file and so fort ). First, I do all the read/write file in the paint method. Not success. The paint method is used to display " You are the visitor of ... " words. Is it have other way to display the words? Afterward, I created the method for the read/write file and called in paint method. Not success. Then, called in init(), not success too. ( The not success means can not display on browser but is when appletviewer )

2 ) At first, I cannot do the write. But not after I added one command in the java.policy file. Everything is go smooth.

3 ) the code is in the try block. But I didn't get any exception after I added the command. Before I added the command, some errors will appear in my screen (MS dos) when appletviewer. Now no.

niliep at 2007-6-29 17:55:42 > top of Java-index,Archived Forums,Java Programming...
# 3

Browsers in general don't use the java.policy file so it doesn't know about your modifications to it. You should get a AccessDeniedException or SecurityException printed in the browser's java console that is if you are working on an applet that uses the browser's default JVM; you are not using the java plugin, are you?

There is only one way of drawing strings:

public void paint(Graphics g) {

g.drawString("Hello World!", 20, 20);

}

It's difficult to miss that...

So my guess is that the problem is really with reading/writing the file.

jsalonen at 2007-6-29 17:55:42 > top of Java-index,Archived Forums,Java Programming...
# 4
Thanks anyway.I will try to check the AccessDeniedException or the SecurityException.Yes, I am not using the java plugin. Is it easier if I use the java plugin? So, do I need to modifier the IE's security? Is it related to what I am doing?
niliep at 2007-6-29 17:55:42 > top of Java-index,Archived Forums,Java Programming...
# 5

> I will try to check the AccessDeniedException or the SecurityException.

See the browser's help on java or console or VM, how to display the console should be mentioned there.

> Yes, I am not using the java plugin. Is it easier if I use the java plugin?

Easier for you or the users? No, it's easier for you to use the appletviewer (but please do set the security settings back to maximum security - this way if something doesn't work in the appletviewer then it wont work in browser either).

Also, any plugin wont help you lowering the security settings of IE and NN.

> So, do I need to modifier the IE's security? Is it related to what

> I am doing?

If _you_ did that then what about the users? "Please turn your security settings to minimum so that my counter applet works".

No, you should have some server side technology to write to the file and then call it from the applet - reading a file from the server in an applet is easy but writing a file is hard. This is why there are practically no applets that can be taken seriously - you can't easily save persistent data anywhere. (And what if the user browser doesn't even have Java enabled?) Server side technologies like JSP or servlets or PHP or perl or cgi are just the thing for web counters...

jsalonen at 2007-6-29 17:55:42 > top of Java-index,Archived Forums,Java Programming...
# 6

ok. Really thanks alot. :-)

At the last sentence. Do you mean that I can use other programming languages to do the counter? Yes I know. But I have to use the Applet. This is my lecturer ask for.

Anyway, thanks alot. I will inform you if I success.

Lastly, I don't know what should I ask about this project. I have no idea.

I am appreciate for it.

niliep at 2007-6-29 17:55:42 > top of Java-index,Archived Forums,Java Programming...
# 7

> Do you mean that I can use other programming

> languages to do the counter?

Nononono....

JSP and servlets are Java. They are server side and thus require some extra setting up (unless someone has done it for you) but they are Java.

PHP, perl and cgi (usually C and C++ but it can be anything) are just other (non-Java) possibilities. There are many others as well...

> But I have to use the Applet. This is my lecturer ask for.

Maybe you could explain him/her that an applet can't easily do this and pick some other project... How about an applet that renders a view of the Mandelbrot set fractal? It's simple and quite fun to code.

Don't get me wrong; there are possibilities to sava data on the server. But you'll need something running back there: a database, a ftp server, a custom cgi/jsp/php/whatever script, ... well, those are the most popular ones. Most web servers have a ftp server running on them for remote uploading of files. It is just that if you can use server side technologies it's easier to make a 100% server side counter...

jsalonen at 2007-6-29 17:55:42 > top of Java-index,Archived Forums,Java Programming...