Experiment 28

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

EXPERIMENT 28

Aim: Develop minimum two basic Applets. Display output with applet
viewer and browser.

a) Develop a program on basic applet.

b) Develop a program using control loops in applets

Program 1: Develop a basic applet to display "Welcome to the World of


Applet".

//Exp28.java

import java.applet.Applet;

import java.awt.*;

public class Exp28 extends Applet

public void paint(Graphics g)

Font font = new Font("Arial", Font.BOLD, 20);

g.setFont(font);

g.drawString("Welcome to the Java Applets....", 50,50);

}
//Exp28.html

<html>

<head>

<title>Basic Applet</title>

</head>

<body>

<applet code="Exp28.class" width="300" height="200">

<applet>

</body>

</html>

Output:
Program 2: Develop a program to implement all methods of applet.

//Exp28_1.java

import java.applet.Applet;

import java.awt.*;

public class Exp28_1 extends Applet

public void init()

System.out.println("\nInitializing applet...");

public void start()

System.out.println("\n Starting applet...");

public void stop()

System.out.println(" Stopping applet...");

public void destroy()

System.out.println("\nDestroying applet...");

}
public void paint(Graphics g)

Font font = new Font("Arial", Font.BOLD, 20);

g.setFont(font);

System.out.println(" Painting applet...");

g.drawString("Welcome to Applet Methods", 20, 20);

//Exp28_1.html

<html>

<head>

<title>All Methods of Applet</title>

</head>

<body>

<applet code="Exp28_1.class" width="300" height="300">

</applet>

</body>

</html>
Output:
Program 3: Develop a program using control loops in applets.

//Exp28_2.java

import java.applet.Applet;

import java.awt.*;

public class Exp28_2 extends Applet

public void paint(Graphics g)

int x = 20, y = 20;

for (int i = 0; i < 5; i++)

g.drawRoundRect(x, y, 50, 50, 10, 10);

x += 70;

//Exp28_2.html

<html>

<head>

<title>Control Loops in Applet</title>

</head>
<body>

<applet code="Exp28_2.class" width="300" height="300">

</applet>

</body>

</html>

Output:

You might also like