Here is the code of a simple program to draw shapes like rectangle, circle, line, etc using java applet. We need two classes to draw the shapes. Graphics method is used here to draw shapes. We are using drawingexample.class as class. See the example :
import java.applet.*;
import java.awt.*;
public class drawingexample extends Applet{
int x=300,y=100,r=50;
public void paint(Graphics g){
g.drawLine(3,300,200,10);
g.drawOval(x-r,y-r,100,100);
g.drawRect(400,50,200,100);
g.drawString("Circle",275,100);
g.drawString("Rectangle",450,100);
g.drawString("Line",100,100);
}
}
Showing posts with label java applet. Show all posts
Showing posts with label java applet. Show all posts
Applet Format
[CODEBASE = codebaseURL]
CODE = appletFile
[ALT = alternateText]
[NAME = appletInstanceName]
WIDTH = pixels
HEIGHT = pixels
[ALIGN = alignment]
[VSPACE = pixels]
[HSPACE = pixels]
>
[< PARAM NAME = appletParameter1 VALUE = value >]
[< PARAM NAME = appletParameter2 VALUE = value >]
</APPLET>
*********************************************
Codebase - It contains the applet's code directory or folder in the URL.
ALT - Display the attributes if the browser unable to run applet code.
WIDTH (in Pixel), HEIGHT (in Pixel) - It is the area in which applet display.
ALIGN - It align the applet display in left, centre, right, top, baseline, bottom, etc. I will explain the rest of the attributes soon.
Java Applets
Definition of Applet :
It is program that can be embedded in HTML documents. It is useful to make website entertaining and more attractive. We can include chat feature using java applet. It runs in the browsers like internet explorer and mozilla, these browsers supports java features.
It can be downloaded here free. http://java.sun.com/j2se/.
A simple program how to display image file using Java applet :
import java.applet.*;
import java.awt.*;
public class appletImage extends Applet{
Image img;
MediaTracker tr;
public void paint(Graphics g) {
tr = new MediaTracker(this);
img = getImage(getCodeBase(), "myimage.gif");
tr.addImage(img,0);
g.drawImage(img, 0, 0, this);
}
}
Subscribe to:
Posts (Atom)