[java] applet questions

Started by
8 comments, last by alexxzius 16 years, 10 months ago
ok, a few noob questions: 1. How do u read and write files when running an applet. I tried using the buffered-stream-stuff and it just flooded me with errors. Is it even possible to make an applet use files? (probably has to do with security or something). 2. My game speed acting weird. For example, my game runs about 50% faster on Firefox than on IE. When i disable my wireless connection, my games speeds up like crazy. When i change the speed from 30 to 40 it slows down. But on 50 its running slower than on 40. I know if yo computer is from 19th century some things run slow cause CPU is 100+ but my CPU is 20%.
Advertisement
1. You should be able to read files okay from an applet... you have to go through the URL to get at the file as opposed to hard coding a file path into a File object... I know that one hit me.

2. You got the same JVM in both browsers? One may be like 1.2.x and the other may be like 1.4.x or something like that... MS java vs Sun Java... it also depends on how you are timing your frames... if it's off of a timer class, that may be it.


Just things to look for... I don't know for sure... I'm new.
Quote:Original post by alexxzius
1. How do u read and write files when running an applet. I tried using the buffered-stream-stuff and it just flooded me with errors. Is it even possible to make an applet use files? (probably has to do with security or something).


Have you signed your applet? You need to sign it in, so that the user may choose whether or not to allow your applet access.

Quote:Original post by alexxzius
2. My game speed acting weird. For example, my game runs about 50% faster on Firefox than on IE. When i disable my wireless connection, my games speeds up like crazy. When i change the speed from 30 to 40 it slows down. But on 50 its running slower than on 40. I know if yo computer is from 19th century some things run slow cause CPU is 100+ but my CPU is 20%.


Bacon and Eggs has some great points, check them out. Make sure your dynamics is time-based and not frame-based.
Best regards, Omid
Quote:
Have you signed your applet? You need to sign it in, so that the user may choose whether or not to allow your applet access.


Well obviusly i dont know how to sign an applet because if i did i would be able to read and write files. How do u sign applets anyways? (what function to use? i could just go and look it up myself)

A thing about speed i found out is that when the amount of sleep time is odd the applet runs faster.
sleep(29) runs faster than sleep(26). Weird . . .

Another question:
When i draw strings on my applet with /n and /t, they dont show up (just ignored)
So if my string is
String mystr="Multiline \nstring";
its displayed like
Multiline string
ok, ive looked through several java books and didnt find nothing about how to sign an applet. The sun tutorials had a few pages about it but it didnt work.
I used the policytool in the command line and created a policy file and done all it said but it didnt work.
Any help ? . . .
You have to sign jars for WebStart as well. There is a tutorial that shows you how at http://www.cokeandcode.com/webstarthowto

If you don't have a requirement to use an applet, it would be better to make an Application that uses WebStart. WebStart has the convenience of an applet, but the power of an application.
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]
im working with applets for now. And i wanna know how to sign an applet not a jar or a webstart . . .
Signing is a complete and pointless redundance. Why not just allow working with files instead of going through all these. Its like sun corp saying "if u 2 dumb to figure out how to sign an applet, u shouldnt use files . . . ".

I figure you gotta tell an applet what policyfile to use or something.
The only way to sign an applet is to put it in a jar.

The reason for it is for the users saftey. If they allowed unsigned applets to do anything, then anyone could just come in and wipe out your hard drive or anything. It is a measure of security.
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]
You shouldn't sign you applet because you're asking the user
to trust you to not trash his machine. Smart users will say
no.

Applets can read files using URLs that access the same server
as the applet was loaded from. Applets being developed can
read files on your development machine using FILE: Urls if
your permissions are set appropriately.

Applets can read directories from your host machine, but they
typically see the directory in the HTML format that your browser
would display for the same URL, some parsing is required.

Applets can also open socket connections back to the original
host, which is how games get run.

---visit my game site http://www.boardspace.net - free online strategy games

ok, so I put my applet in a jar, but the browser wont display it. It gives me a bunch of Unknown Source errors (?).
The HTML code is

<applet code=applet1.class archive=applet1.jar width=400 height=300 >

I figured out how to make applet read files through URLs, but still dont know how to write files. . .
::skull::

This topic is closed to new replies.

Advertisement