Java Tutorial
We need to import Abstract Window Toolkit(AWT) classes. AWT supports window based graphical interface. Once imported AWT classes, need to extend Applet class and subclass must be public which will be accessed by code. paint() method must be overridden by the applet program, this paint method will be called that the applet must redisplay its output.
// java applet program example: import java.awt.*; import java.applet.*; /* <applet code="JavaAppletTest" width=500 height=200> </applet> */ public class JavaAppletTest extends Applet { public void paint(Graphics gr) { //Writes text in the applet window. gr.drawString("Java Applet Test", 20, 30); } }
1) Compile the applet program: javac JavaAppletTest.java 2) Create the html file 'RunJavaAppletTest.html' <applet code="JavaAppletTest" width=500 height=200> </applet> 3) Run th appletviewer command to see the output in appletviewer. $ appletviewer RunJavaAppletTest.html
<html> <body> <applet code="JavaAppletTest.class" width=500 height=200> </applet> </body> </html>
Java Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us | Report website issues in Github | Facebook page | Google+ page