0% found this document useful (0 votes)
121 views

1) Develop A Java Program To Draw An Applet of Size 300X200 That Prints "Hello World" Text On The Applet Window. Source Code: Helloworldapplet - Java

1) The document describes 6 Java applets that were developed as part of a practical assignment. The applets include programs to print "Hello World", use HTML parameters, draw a rainbow, create a chess board, draw a smiley face, and draw a house using different shapes. 2) Each applet is demonstrated through the provided source code and an output screenshot. The code uses classes like Applet, Graphics, and AWT shapes to draw the images. 3) The assignment involves developing basic Java applets that print text, use parameters, and draw simple images like shapes, faces and objects using graphics methods.

Uploaded by

B.J Nakum
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
121 views

1) Develop A Java Program To Draw An Applet of Size 300X200 That Prints "Hello World" Text On The Applet Window. Source Code: Helloworldapplet - Java

1) The document describes 6 Java applets that were developed as part of a practical assignment. The applets include programs to print "Hello World", use HTML parameters, draw a rainbow, create a chess board, draw a smiley face, and draw a house using different shapes. 2) Each applet is demonstrated through the provided source code and an output screenshot. The code uses classes like Applet, Graphics, and AWT shapes to draw the images. 3) The assignment involves developing basic Java applets that print text, use parameters, and draw simple images like shapes, faces and objects using graphics methods.

Uploaded by

B.J Nakum
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Advanced Java Programming (3360701) 196020307083/EnrolmentNo

Practical – 1.1
1) Develop a java program to draw an applet of size 300x200 that prints
“Hello World” text on the Applet window.

Source Code: HelloWorldApplet.java

import java.awt.Graphics;
import java.applet.Applet;

/*
<Applet code="HelloWorldApplet.class" width= 300 height=200 >
</Applet>
*/

public class HelloWorldApplet extends Applet {


public void paint(Graphics g)
{
g.drawString("Hello World",20,50);
}
}

▪ Output:

Computer Engineering 1
A. V. Parekh Technical Institute, Rajkot
Advanced Java Programming (3360701) 196020307083/EnrolmentNo

Practical – 1.2
2) Develop a java program to print the message passed using HTML file
using <PARAM> tag.

▪ Source Code : ParamApplet.java

/*<applet code="ParamApplet.class" width=500 height=200>


<param name="a" value="7"/>
<param name="b" value="7"/>
</applet>*/
import java.awt.*;
import java.applet.Applet;

public class ParamApplet extends Applet


{
int a,b;
public void init()
{
a=Integer.parseInt(getParameter("a"));
b=Integer.parseInt(getParameter("b"));
}
public void paint(Graphics g)
{
g.drawString((a+b)+"",20,30);
}
}

Computer Engineering 2
A. V. Parekh Technical Institute, Rajkot
Advanced Java Programming (3360701) 196020307083/EnrolmentNo

▪ Output:

Computer Engineering 3
A. V. Parekh Technical Institute, Rajkot
Advanced Java Programming (3360701) 196020307083/EnrolmentNo

Practical – 1.3
3) Develop a java applet to draw a Rainbow (using arc).

▪ Source Code : Rainbow.java

/*<APPLET code="Rainbow.class" width="500" height="300">


</APPLET>
*/
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;

public class Rainbow extends Applet


{
public void paint(Graphics g)
{
g.setColor(Color.red);
g.fillArc(120,120,150,150,0,180);

g.setColor(Color.orange);
g.fillArc(125,125,140,140,0,180);

g.setColor(Color.yellow);
g.fillArc(130,130,130,130,0,180);

g.setColor(Color.green);
g.fillArc(135,135,120,120,0,180);

g.setColor(Color.cyan);
g.fillArc(140,140,110,110,0,180);

g.setColor(Color.blue);
g.fillArc(145,145,100,100,0,180);

g.setColor(Color.magenta);
g.fillArc(150,150,90,90,0,180);

}
}

Computer Engineering 4
A. V. Parekh Technical Institute, Rajkot
Advanced Java Programming (3360701) 196020307083/EnrolmentNo

▪ Output:

Computer Engineering 5
A. V. Parekh Technical Institute, Rajkot
Advanced Java Programming (3360701) 196020307083/EnrolmentNo

Practical – 1.4
4) Develop a java applet to create a Chess Board.

▪ Source Code : ChessBoard.java

import java.applet.Applet;
import java.awt. *;
/* <applet code="ChessBoard.class" width=300
height=200></applet> */
public class ChessBoard extends Applet
{
public void paint(Graphics g)
{
int f=0;
for(int i=0,k=0;k<8;i+=40,k++)
for(int j=0,l=0;l<8;j+=40,l++)
{
f=k+1;
if((f%2)==0)
{
g.drawRect(j+40,i,40,40);
f++;
}
else
{
g.fillRect(j+40,i,40,40);
f++;
}
}
}
}

Computer Engineering 6
A. V. Parekh Technical Institute, Rajkot
Advanced Java Programming (3360701) 196020307083/EnrolmentNo

▪ Output:

Computer Engineering 7
A. V. Parekh Technical Institute, Rajkot
Advanced Java Programming (3360701) 196020307083/EnrolmentNo

Practical – 1.5
5) Develop a java applet to create a Smiley Emoji with appropriate color.

▪ Source Code : Smiley.java

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;

/* <applet code="Smiley.class" width=500 height=600></applet>


*/

public class Smiley extends Applet


{
public void paint(Graphics g)
{
g.setColor(Color.blue);
g.fillOval(100,50,250,250);

g.setColor(Color.black);
g.fillOval(150,120,50,50);

g.setColor(Color.black);
g.fillOval(250,120,50,50);

Color c=new Color(207,207,207);


g.setColor(Color.black);
g.fillArc(180,200,100,60,180,180);
}
}



Computer Engineering 8
A. V. Parekh Technical Institute, Rajkot
Advanced Java Programming (3360701) 196020307083/EnrolmentNo

▪ Output:

Computer Engineering 9
A. V. Parekh Technical Institute, Rajkot
Advanced Java Programming (3360701) 196020307083/EnrolmentNo

Practical – 1.6
6) Develop a java applet to create a House using different shapes.

▪ Source Code: House.java

/* <APPLET Code="House.class" width="1000" height="1000">


</APPLET> */
import java.awt.*;
import java.applet.Applet;

public class House extends Applet


{
public void paint(Graphics g)
{
int x[]={330,530,429,120,0,0};
int y[]={300,300,120,120,0,0};
g.setColor(Color.magenta);
g.fillPolygon(x,y,3);
g.drawPolygon(x,y,3);
g.setColor(Color.red);
g.fillOval(397,227,70,70);
g.drawOval(397,227,70,70);
g.setColor(Color.blue);
g.fillRect(330,300,200,275);
g.drawRect(330,300,200,275);
g.setColor(Color.cyan);
g.fillRect(460,370,50,50);
g.drawRect(460,370,50,50);
g.setColor(Color.cyan);
g.fillRect(360,370,50,50);
g.drawRect(360,370,50,50);
g.setColor(Color.green);
g.fillRect(410,475,50,100);
g.drawRect(410,475,50,100);
g.setColor(Color.yellow);
g.fillRoundRect(315,575,230,25,10,10);
g.drawRoundRect(315,575,230,25,10,10);
}

Computer Engineering 10
A. V. Parekh Technical Institute, Rajkot
Advanced Java Programming (3360701) 196020307083/EnrolmentNo

▪ Output:

Computer Engineering 11
A. V. Parekh Technical Institute, Rajkot
Advanced Java Programming (3360701) 196020307083/EnrolmentNo

Computer Engineering 12
A. V. Parekh Technical Institute, Rajkot

You might also like