File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes System.exit(0) applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "System.exit(0) applet" Watch "System.exit(0) applet" New topic
Author

System.exit(0) applet

Arun Maalik
Ranch Hand

Joined: Oct 25, 2005
Posts: 216
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class first extends JApplet implements ActionListener{
JButton btn=new JButton("EXIT");

public void init(){
Container con=getContentPane();
con.add(btn);
btn.addActionListener(this);
}

public void actionPerformed(ActionEvent ae){
String st=ae.getActionCommand();
if("EXIT".equals(btn))
System.exit(0);


}
}

Helo frnd above code is runing fine its size and other information i have decleared in first.html. I whish that when i click on EXIT button of applet as soon as the applet window should be closed that's why i have implement System.exit(0) method in if statment of actionPerformed method but it is not working why? is there any problem with exit command or somthing else.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41835
    
  63
You're comparing "EXIT" to "btn", when you should be comparing it to "st".

This will cause appletviewer to quit, but you're aware that it won't cause a browser to quit, right?


Ping & DNS - my free Android networking tools app
Arun Maalik
Ranch Hand

Joined: Oct 25, 2005
Posts: 216
Sorry sir By the above code applateviewer also not quiting


I would like a statment that should quit at least appletviewer what statment should i add in place of that System.exit(0) pls tell me.


Regard
Arun
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41835
    
  63
You're right, you're also missing a

btn.setActionCommand("EXIT");

If then you get an "access denied" exception, that means that the appletviewer you're using enforces the applet sandbox restrictions. The two principal ways around that -signed applets and policy files- are described on this wiki page.
[ July 14, 2006: Message edited by: Ulf Dittmer ]
Arun Maalik
Ranch Hand

Joined: Oct 25, 2005
Posts: 216
But Sir still it is not working I have allready added ststment what U told me.

With Regard

Arun kumar maalik
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Arun Maalik
Ranch Hand

Joined: Oct 25, 2005
Posts: 216
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class today extends JApplet implements ActionListener{

JButton btn=new JButton("EXIT");

Container cont;
public void init(){
cont=getContentPane();
cont.setLayout(null);
btn.setBounds(50,50,90,30);
cont.add(btn);
btn.addActionListener(this);
btn.setActionCommand("EXIT");
}

public void actionPerformed(ActionEvent ae){
JButton button = (JButton)ae.getSource();
String st = button.getActionCommand();

// to identify the button by its reference
if(button == btn)
System.exit(0);
// to identify the button by its actionCommand

/* if("EXIT".equals(st))
System.exit(0);*/
}
}
OOOOPS sir there are a lot of exception are thrown when i m using above code now i have more eager to know How a button event will work when i m working with Button well provide me a bit a tested code so that i can run that code on my computer

wit regard

Arun
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41835
    
  63
Arun, you need to put a little effort into it. The least you can do is to post the exceptions you're getting, which will enable us to take a guess at what's going wrong. You could also work through the button section of the Java tutorial to learn concepts such as action listeners.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: System.exit(0) applet