An applet is a special code of Java programs. Java applets is very easy way to draw graphics related diagrams. In java applets drawing string, drawing rectangle, drawing oval, drawing fill rectangle, drawing fill oval, add buttons, add panels, add labels, add list etc. are easy to handle in java applet programs. Below java applet example will be show the first applet string with its location. That is height and width of position of the string.
Simple Applet Program in java is attached below with simple example. You need to embed html code run this applet programming in java is also included below program.
Program for applets in java with Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import java.awt.*; import java.applet.*; public class WelcomeApplet3 extends Applet { public void init() { } public void paint(Graphics g) { // applet programming in java paint loop g.drawString("Welcome to Java Programming!", 25, 25 ); g.drawLine (15, 10, 210, 10); g.drawLine (15, 50, 260, 50); g.setColor(new Color(255, 215,0)); g.fillRect(50,80,50,80); g.setColor(Color.RED); g.fillOval(120,120,200,200); } } /* <applet code="WelcomeApplet3.class" width="300" height="300"> </applet> */ //Start Java applets code /* <applet code="FirstApplet.class" width="300" height="300"> </applet> */ //End of java applets code // end of java applets program |