The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
October 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Coverting An Applet To An Application

Posted by Matt Gerrans on January 26, 2002 at 5:27 PM

Just add this main() method to your class:


public static void main(String[] args)
{
Applet applet = new Checkers();
javax.swing.JFrame frame = new javax.swing.JFrame("Checkers");
// To close the application:
frame.setDefaultCloseOperation( javax.swing.JFrame.EXIT_ON_CLOSE );
frame.getContentPane().add(applet);
frame.setSize(400,300);
applet.init();
applet.start();
frame.setVisible(true);
}

Note that I used JFrame, which is a Swing component, whereas you were only using AWT. If you don't want to add Swing to the mix, you can easily change it to use Frame instead and add a window listener in place of the setDefaultCloseOperation() that looks like this:


frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us