Java basic applet code is shown as below that loads an applet window and draws a string as an output with the help of paint method.
java basic applet code is shown as below that loads an applet window and draws a string as an output with the help of paint method.
import java.awt.*;
import java.applet.*;
/**/
public class AppDemo extends Applet
{
public void paint(Graphics g)
{
g.drawString(”writing4angels”,200,200);
}
}
Execute the above code by first compiling the program and then using the appletviewer tool to test the applet. Applet is a web based dynamic program that executes in a web browser. But here we are testing the applet that can be later embedded in to web browser.
Compile the code on command prompt as follows:
javac AppDemo.java
Now, use appletviewer on command prompt to execute the program as follows:
appletviewer AppDemo.java
In the program shown here, there is a paint() method used to draw on the applet window. Here drawString() method is used with a string as an argument and it will be drawn on applet at 200 x and y axis position.












Leave Your Response