How to Learn Java Applet
Java applets are small applications (hence the name 'applet') developed using an object-oriented programming language called Java, developed by Sun Microsystems in 1991 to 1994. Java applications can run in any operating system environment, and can deploy in most web browsers (with small tweaks for some browsers, such as Netscape). You can use Java applets to spice up your web pages by extending functionality, user interface and appearance. You can preview and download free sample applets from developer websites and modify the existing code to suit your needs. You need to have a basic grasp of software coding and deployment, particularly in Java and Hypertext Markup Language (HTML).
Instructions
-
Learning Java Applets
-
1
Find the resource that provides the tutorial you can work with. You can purchase or borrow books on Java development, or you can search for tutorials on the Internet.
-
2
Develop your Java applets using the examples provided in the tutorials. You can use the following sample 'Hello World' applet from the Sun website:
import javax.swing.JApplet;
import java.awt.Graphics;public class HelloWorld extends JApplet {
public void paint(Graphics g) {
g.drawRect(0, 0,
getSize().width - 1,
getSize().height - 1);
g.drawString("Hello world!", 5, 15);
}
}
This sample code displays a rectangular box, which shows the message: "Hello world!" in the body of your website. -
-
3
Save your applet with the .class file extension, for example: urname.class.
-
4
Test your applets for functionality in the JRE. The more complicated the features you include, the more you need to test the applet.
-
5
Revise the code as necessary, and then save your source files (including all images and graphics) as "All Files," "Source" or "Raw Data," depending on the operating system you are using.
-
6
Save the applet source files in one directory of the server where you deploy your web page.
-
7
Embed your applet in the <BODY> area of your HTML page by adding the following call command:
<APPLET CODE="urname.class" WIDTH="1" HEIGHT="1">
</APPLET>
The first line of code calls the applet you made, and then displays it in a box defined by the width and height parameters. The second line ends the call for your applet. -
8
Review the web page to determine how your applet is functioning.
-
9
Revise your Java applet as necessary.
-
1
Tips & Warnings
Download only free applets for your use, do not use or modify copyrighted materials. Experiment with different types of Java applets to enhance your website. Improve your website and develop your skills by learning how to code using JavaScript, and implementing cascading style sheets (CSS).