calling System.exit(0) from an applet
Hello,
I have a weird problem.
First... my applet has full permissions in the java.policy file.
problem:
When I call System.exit(0) from the applet (jbutton's action listener), the applet disappears from the browser window and the browser freezes.
but
if I display a messagedialog (JoptionPane) before calling System.exit(0) ... everything works fine (after I press ok on the message dialog, the browser window disappears)
here's my code
<CODE>
public class testApp extends JApplet{
public void init(){
System.err.println("hello");
JButton button = new JButton("Exit");
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(new JFrame(),"Exiting...");
System.exit(0);
}
});
this.getContentPane().add(button);
}
}
</CODE>
what am I missing?
[981 byte] By [
fsaff] at [2007-9-26 3:32:35]

sorry here's the code... (formatted)
public class testApp extends JApplet{
public void init(){
System.err.println("hello");
JButton button = new JButton("Exit");
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(new JFrame(),"Exiting...");
System.exit(0);
}
});
this.getContentPane().add(button);
}
}
fsaff at 2007-6-29 12:00:20 >

hey fsaff,
I know this is off the subject, but I would REALLY REALLY appreciate if you could tell me how your applet has full permissions inside of the browser. This is something that I have been working on for a very long time and I have not been successful. I have all the cabarc and other signing tools, but I just cant seem to do everything right. I have an applet that needs to know how to read and write to the clients local computer. Any help would be appreciated (steps, references to articles, books, or whatever helped you learn it).
Thanks in advance.
Hi!
i feel that the button should be added in the init() of the applet.so that when the user clicks the button, the respective actionPerformed will be invoked accordingly. AND set the applet visibility to false.
try rewriting the init method of the Applet like the following:-public class TestApp extends JApplet implements ActionListener
{
public void init()
{
System.err.println("hello");
JButton button = new JButton("Exit");
button.addActionListener(this);
this.getContentPane().add(button);
}
public void actionPerformed(ActionEvent e)
{
this.setVisible(false);
JOptionPane.showMessageDialog(new JFrame(),"Exiting...");
}
}
zag at 2007-6-29 12:00:21 >

an applet has security restrictions that forbids it from accessing a client file system. BUT there are ways like signing your applet or just asking the user to change the security setting when he calls the applet.
This link shows the steps involved in signing an applet very clearly. :-http://developer.java.sun.com/developer/technicalArticles/Security/Signed/
Or the user(client) can go to the "Internet Option" under the Tools of the web browser(IE). Go to security and change to custom security for the Internet.(Caution the user needs to return the security to default after finishing accessing the applet). Click to "Custom Java Setting" button. If you don't see a "Custom Java Setting" button below then scroll down to "Java Permissions" option and select custom. Now you will see the "Custom Java Setting" button. Go there and select "edit permission" tab. Under "Unsigned Content" select enable. This will grant full permission.
zag at 2007-6-29 12:00:21 >

Hello ...
sorry for the delay ...
well the way we're handling it is through the java.policy file ...
the application we're developping is for internal use and requires the client to have JRE 1.3.1 installed.
if a client whishes to use our applet he/she has to edit the c:\program files\javasoft\jre\1.3.1\lib\security\java.policy file and the following text:
grant codeBase "http://destiny/mpt/-" {
permission java.security.AllPermission;
};
where http://destiny/mpt is the location of the jar file...
I never was able to figure out the signing either .. :)
fsaff at 2007-6-29 12:00:21 >
