java applet program question (on getting path fails)
Code Java:
import java.applet.Applet;
import java.awt.Graphics;
import java.io.*;
import java.awt.Color;
public class chatbox extends Applet {
public String test()
{
setBackground(Color.white);
String fileName = System.getProperty("user.home") +
System.getProperty("file.separator") + "newfile";
String msg = "This message was written by a signed applet!!!\n";
String s ;
try {
FileWriter fos = new FileWriter(fileName);
fos.write(msg, 0, msg.length());
fos.close();
s = new String("Successfully created file :" + fileName);
} catch (Exception e) {
System.out.println("Exception e = " + e);
e.printStackTrace();
s = new String("Unable to create file : " + fileName);
}
return s;
}
public void paint(Graphics g)
{
g.setColor(Color.blue);
g.drawString("Signed Applet Demo", 120, 50);
g.setColor(Color.magenta);
g.drawString(test(), 50, 100);
}
}
Running this in regular java it works. RUnning it in an applet it fails. test() for example is where it should show a string of the cache path.
System.getProperty("user.home") fails in general when requesting it.
Is there any way to still do this without it failing. Like a way to ask users permission to run.
Re: java applet program question (on getting path fails)
From your problem description, it seems like you are working on MAC OS.
Anyways, you should make a static method to read this path that would execute before any action performed.
Hope this will help.
Re: java applet program question (on getting path fails)
Re: java applet program question (on getting path fails)
No I am working on windows number 1
Number 2, can someone give me an example of how to sign in an applet so I can get this to work.
Re: java applet program question (on getting path fails)
Or if there is a way to tell users I am getting their path so they can accept it.
Re: java applet program question (on getting path fails)
Thank second link leads you to the best step by step description I've found. Worked for me the first time through, but your mileage may vary.
Re: java applet program question (on getting path fails)
Signing in applets somehow pissed me off.
I hate the restrictions. I know you have to get certified and everything but we have to wait days just to get certified. Why couldn't it just be. Hello java is trying to activate you, Do you accept permissions to let java run.