How to Make a Java Applet

Applets came with a great promise of embedding software into web pages. It is very powerful if used properly. They are used by some banks for client login, which speaks greatly of its security features. Download and install JDK from...

Part 1 of 4:

Setting up the Environment

  1. Picture 1 of How to Make a Java Applet
    Download and install JDK from http://java.sun.com/javase/downloads/index.jsp.
    1. Download and install some Java IDE, to make things easier. Netbeans or Eclipse are good Open Source tools.
  2. Picture 2 of How to Make a Java Applet
    Make a folder for your source codes and projects.
Part 2 of 4:

Testing the Sample Applet

  1. Picture 3 of How to Make a Java Applet
    Open NotePad and copy and paste the code in the code section.
  2. Picture 4 of How to Make a Java Applet
    Click file, and then click save as, and save it in your java folder but name the code "test.java" (without quotation marks)
  3. Picture 5 of How to Make a Java Applet
    Exit the window and click start, run, then type in cmd in the box and hit ok.
  4. Picture 6 of How to Make a Java Applet
    Type cd C:jdk6bin and hit enter
  5. Picture 7 of How to Make a Java Applet
    Type javac then C:javatest.java and hit enter.
  6. Picture 8 of How to Make a Java Applet
    Now copy and paste the launcher into NotePad and Click file, and then click save as, and save it in your java folder but name the launcher. "test.htm" (without quotation marks).
  7. Picture 9 of How to Make a Java Applet
    Now go to the java folder you made and launch the test.htm file.
Part 3 of 4:

Embedding a Java program into an applet

  1. Note: You need to know how to program Java in order to make your own applet.
  1. Picture 10 of How to Make a Java Applet
    Open your MAYANK of choice or a simple text editor (like notepad in windows).
  2. Picture 11 of How to Make a Java Applet
    Code a Java program to do something. Make it a subclass of JPanel[1], so you can put it into a top level swing container like a JApplet[2] or a JFrame[3]
  3. Picture 12 of How to Make a Java Applet
    Create a basic JApplet to launch your JPanel program.
    1. Override the
      start()
      method, get a reference to the contentPane, add your JPanel to it and repack the Applet.
      1. You might need to fine-tune the component allocation on the JPanel, to better fit the applet window.
  4. Picture 13 of How to Make a Java Applet
    Use the same procedure as for compiling and loading the sample applet to pack your program and run it on the basic launcher.
Part 4 of 4:

Sample Code

Basic "Hello World" Applet

import java.awt.*; import java.applet.Applet ; public class test extends Applet { public void paint (Graphics g) { g.drawString("Hello World!", 80, 80); g.drawString("This Is My First JAVA Code!!!!",100,100); } } 

HTML Launcher

<title> My Applet title> <applet code="test.class" Width = 700 height = 400> applet> 
Update 05 March 2020
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile