This assumes, of course, that you have a fairly basic application with nothing terribly fancy in the GUI. It also assumes that you have created your application as a single file extending the JFrame class as I demonstrated in class.
- Add import java.applet.*; to your import statements.
- Make your GUI class extend JApplet rather than JFrame.
- Remove all calls to JFrame methods, specifically the methods
- Change your constructor heading to public void init ().
- Remove your main() method entirely. Yes, really.
Now you have an applet, which you can run either in the applet viewer component of your favorite IDE, or you can copy the ridiculously barebones HTML code given below into a text file with an .html file extension on the name to run it in an actual web browser. Notice that the HTML file does, in fact, use the deprecated <applet> tag because of cross-browser compatibility issues. If you want to know more about this, this page at Oracle’s web site will tell you more than you want to know.
<title>Example Java Applet</title>
<applet code = "ExampleGUIApplet.class" width = 300 height = 400 />