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

Java Practical

The document contains code to draw several basic shapes using graphics and applets in Java, including: 1) A face with eyes, nose, mouth, and other features 2) A cylinder 3) A cube 4) A square inside a circle 5) A circle inside a square The code samples use methods like drawOval, drawRect, drawLine, and fillOval to render the shapes to the screen within an applet.

Uploaded by

sarvesh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views

Java Practical

The document contains code to draw several basic shapes using graphics and applets in Java, including: 1) A face with eyes, nose, mouth, and other features 2) A cylinder 3) A cube 4) A square inside a circle 5) A circle inside a square The code samples use methods like drawOval, drawRect, drawLine, and fillOval to render the shapes to the screen within an applet.

Uploaded by

sarvesh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Practical No:-29

1. Write a program to create animated shape using graphics and


applets. You may use following shapes:
a) Lines and Rectangles
b) Circles and Ellipses.
c) Arcs
d) Polygons with fill Polygon method.
Write a program to implement an applet to draw basic animated
shapes.
import java.applet.*;
import java.awt.*;
/*<applet code="cartoonD.class" width=500 height=500>
</applet>*/
public class cartoonD extends Applet
{
public void paint(Graphics g)
{
g.setColor(Color.blue);
g.fillOval(50,50,400,400);
g.setColor(Color.black);
g.drawOval(50,50,400,400); //OUTER CIRCLE
g.setColor(Color.white);
g.fillOval(75,115,350,335);
g.setColor(Color.black);
g.drawOval(75,115,350,335);//INNER CIRCLE
g.setColor(Color.white);
g.fillOval(165,70,85,120);
g.setColor(Color.black);
g.drawOval(165,70,85,120);// FIRST EYE OUTER
g.fillOval(200,120,30,46);
g.drawOval(200,120,30,46);//1 EYE INNER
g.setColor(Color.white);
g.fillOval(208,130,14,26);
g.setColor(Color.black);
g.drawOval(208,130,14,26);//1LEED
g.setColor(Color.white);
g.fillOval(250,70,85,120);
g.setColor(Color.black);
g.drawOval(250,70,85,120);//SECOND EYE OUTER
g.fillOval(270,120,30,46);
g.drawOval(270,120,30,46);//2 EYE INNER
g.setColor(Color.white);
g.fillOval(278,130,14,26);
g.setColor(Color.black);
g.drawOval(278,130,14,26);//2LEED
g.setColor(Color.red);
g.fillOval(230,170,40,40);
g.setColor(Color.black);
g.drawOval(230,170,40,40);//NOSE
g.drawLine(250,210,250,300);//NOSE LINE

g.setColor(Color.red);
g.fillArc(105,185,290,230,180,180);
g.setColor(Color.black);
g.drawArc(105,185,290,230,180,180);//MOUTH
g.drawLine(105,300,395,300);//MOUTH LINE
g.drawLine(110,190,210,220);//M
g.drawLine(105,245,210,250);//M
g.drawLine(100,290,210,280);//M
g.drawLine(290,220,390,190);//M
g.drawLine(290,255,395,245);//M
g.drawLine(290,280,400,290);//M
}}
Output:-
Practical No.30
1. Develop a program to draw following shapes,graphics and applets.
a. Cilinder

import java.awt.*;
import java.applet.*;
/*<applet code="cilinder.class" width=500 height=500>
</applet>*/
public class cilinder extends Applet
{
public void paint(Graphics g)
{
g.drawOval(10,10,50,10);
g.drawOval(10,80,50,10);
g.drawLine(10,15,10,85);
g.drawLine(60,15,60,85);
}
}
Output:-
b.Cube

import java.awt.*;
import java.applet.*;
/*<applet code="cube.class" width=300 height=300>
</applet>*/
public class cube extends Applet
{
public void paint(Graphics g)
{
g.drawRect(80,10,50,50);
g.drawRect(95,25,50,50);
g.drawLine(80,10,95,25);
g.drawLine(130,10,145,25);
g.drawLine(80,60,95,75);
g.drawLine(130,60,145,75);
}
}
Output:-
2. Develop a program to draw any one of the following:

a. Square Inside a Circle


import java.awt.*;
import java.applet.*;
/*<applet code="Squarecircle.class" width=300 height=300>
</applet>*/
public class Squarecircle extends Applet
{
public void paint(Graphics g)
{
g.drawOval(180,10,80,80);
g.drawRect(192,22,55,55);
}
}
Output:-

b.Circle inside a square


import java.awt.*;
import java.applet.*;
/*<applet code="circlesquare.class" width=300 height=300>
</applet>*/
public class circlesquare extends Applet
{
public void paint(Graphics g)
{
g.drawRect(290,10,80,80);
g.drawOval(290,10,80,80);
}
}
Output:-

You might also like