Want to get started on developing JAVA applets? These few quick and easy steps can help you get going in no time.
If you are still not familiar on developing JAVA applications. Click here to get you started on JAVA.
In this tutorial we will be making use of the Eclipse IDE(Integrated Development Environment). If you do not know eclipse yet start with this tutorial here.
First step in making a JAVA Applet is to make a new JAVA project in your Eclipse IDE.
Click on File... then select New... then click on Java Project....
Choose a Project Name and click Finish...
Now you have your project... we can start coding... :D
Right click on the src folder and choose New... then choose Class
then choose your Class Name and Package name. In our case use
Package -> com.wfdb
Class Name -> HelloApplet
then click on Finish...
Our new Class file will now look something like this...
Now its time to code our Java Applet
First we have to extend our HelloApplet Class by adding
public class HelloApplet extends Applet {
This means we are extending the functionalities of the Applet Class to our HelloApplet Class
Next we add some functionality to our applet...
We add a simple paint method which overrides the method from the Applet Class and use it to draw a String
public void paint(Graphics g) {
g.drawString("Hello World", 25, 25);
}
g.drawString("Your Text Here", x, y); <-- This method paints a Text on x and y coordinates
Next is we add the imports at the top of our HelloApplet Class
import java.applet.Applet;
import java.awt.Graphics;
Our code should now look something similar to this
Now to run our code...
Right click on our HelloApplet.java Class file from our Project choose Run As... and choose Java Applet...
We should now see a small window pop up and display out Text...
There you have it....
You made your first Java Applet...
Keep on checking my blog for new Java Applet Tutorials.... :D
No comments:
Post a Comment