How to Make an Applet With Eclipse for Java

Eclipse is a powerful free and open-source Integrated Development Environment (IDE) originally designed for Java developers in 2001, which has since expanded to include projects covering multiple languages and platforms. Among other tasks, it is an ideal environment for producing applets, special Java programs designed to be embedded within Web pages to provide interactive Web content.

...

Step

Create a new project by clicking "File" and "New Project." Name it "Applet Tutorial."

Step

Click the "Workbench" button to open your newly created project.

Step

Create a new class by clicking "File" and "New Class." The name is "MyApplet." Next to "Superclass," click "Browse." Type "java.applet.Applet" and click "OK." Click the "Generate Constructors from superclass" box.

Step

Paste the following class definition within the source code for MyApplet.java:

Step

public class MyApplet extends Applet implements ActionListener { Label label1 = new Label("Hello World."); Button button1 = new Button("OK");
}

Step

Add import statements for all the objects used in the above code. To do this, go through "ActionListener," "Label" and "Button," and, while the cursor is within that word, press "Ctrl-1" (or "Cmd-1" on Mac). Select "Import" from the list to allow Eclipse to perform the imports automatically. Finally, press "Ctrl-1" over "MyApplet" and choose "Add Unimplemented Methods." This will create an "actionPerformed" method to react to the user clicking the button.

Step

Define the user interface elements just below the class declaration:

Step

public class MyApplet extends Applet implements ActionListener {

Step

Paste the following code within the constructor:

Step

Paste the following code within the "actionPerformed" method that was automatically generated in Step 5: