Home Java Java-tips 45examples 10basic_windows This file defines an applet.

Ask Questions?

View Latest Questions


 
 

This file defines an applet.
Posted on: July 22, 2006 at 12:00 AM
This template is a reasonable way to start an applet, where GenericPanel is a subclass of JPanel and it contains the code to build a GUI with the appropriate listeners.

Java Notes

Example - Generic Applet

This file defines an applet. This template is a reasonable way to start an applet, where GenericPanel is a subclass of JPanel and it contains the code to build a GUI with the appropriate listeners.

This will work for many applets, but there are additional methods that might be implemented if parameters or animation are used.

In the following code following things are done:

  • Applet is extended from GenericApplet class
  • Then in the constructor following code is written

 public GenericApplet {
this.getContentPane().add(new GenericPanel());
}//end constructor

The above code adds the GenericPanel object to contentpage.

 

Example code:

You can learn from the following code listing

// GenericApplet.java - A template for applets.
// Fred Swartz, 2003-Apr

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;


//////////////////////////////////////////////////// class GenericApplet
class GenericApplet extends JApplet{

    //====================================================== constructor
    public GenericApplet {
        this.getContentPane().add(new GenericPanel());
    }//end constructor
}//endclass GenericApplet
The text from the above example can be selected, copied, and pasted into an editor. The boxes will be ignored.
Copyleft 2003 Fred Swartz MIT License, Last update: 2003-10-29

Related Tags for This file defines an applet.:
cguifileclasslistuijpaanimationparametersbuildapplettemplateiomethodsmethodsedapplegenericparameterpanelriathisaisubclasscpantarappjpanellistenerdefinestartifforaddwherewithworktoramcontainslistenerscpanelldeilitliuseimmanartinsubasstamntparreasontempddadditionletjadclesemlistenmeproppparampanssusodefinesstaratanypanelatekishaimplementedllmetermpleaandarcodcodertssrithbcstabablatiaphatfinmanypleplpropprmindodsodeono