Differences Between Extending JApplet and Applet

     

You can use either one. Because JApplet actually extends Applet, much of the functionality is identical. There are a few differences, however.

With JApplet, you have access to the content pane, which can be called using getContentPane() . If you have a content pane of your own (such as a panel) that you want to replace it with, you can call setContentPane() . When you add components to your applet, you add them to the content pane, not the frame.

graphics/fridge_icon.jpg

FRIDGE

Dude. Make sure you write an HTML page that can display your applet. That is the purpose of applets ”to be called from within HTML. Just because it is called appletviewer doesn't mean you pass it the name of the applet class. Pass it the name of the HTML file that references the applet class. I know I just said it, but boy does that happen a lot.


Also, you get the Metal look and feel by default. If you are on Windows, for example, and want to make your applet look like Windows, you need to manually switch to Native look and feel.

BorderLayout, not FlowLayout, is the default layout.

Lastly, you use the paintComponent() method ( not paint() ) to render your text and graphics.

Viewing Applets

There are two ways to view an applet you write: via Web page and with the appletviewer utility that ships with the JDK. Let's write a quick applet, view it in with the appletviewer tool , and then view it in a browser. Note that both ways of viewing an applet require an HTML page. The only way you can get out of writing the HTML page for testing purposes is with an IDE. For example, if you are using Eclipse (free from www.eclipse.org) to write your Java code. Write your applet class, and then click Run... > Java Applet . Works like a champ. Of course, you need to write the HTML once you go to deploy .



Java Garage
Java Garage
ISBN: 0321246233
EAN: 2147483647
Year: 2006
Pages: 228
Authors: Eben Hewitt

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net