| UglyDave |
right folks
i've written an applet which retrieves a clients local machine username and writes it to a file.
however, when i the applet as an applet, it doesn't work.
when i run it in BlueJ (by creating an object & calling the methods), it works perfectly.
i didn't write all the code myself, some came from another app.
here's the code:
code:
import java.applet.*;
import java.awt.Graphics;
public class ntApplet extends Applet {
public String userName = "unknown";
public void init(){
try {
com.sun.security.auth.module.NTSystem ntSystem = new com.sun.security.auth.module.NTSystem();
userName = ntSystem.getName();
toFile(getUserName());
System.out.println(getUserName());
} catch (Exception e) {
System.out.println("Error : " + e + "\n");
}
}
public void paint (Graphics g){
super.paint(g);
g.drawString("Username:"+userName, 25,25);
}
public void toFile(String st){
try{
file f = new file("users.txt");
f.openForAppend();
f.print(st);
f.close();
} catch (Exception e){
System.out.println("Error: " + e );
}
}
public String getUserName() {
return this.userName;
}
}
and the html:
code:
| | |