You are on page 1of 3

Exp No -5

AIM - To Implement Graphics class and awt in java using


Netbeans .
A) Code a smile face .
B) Code of 4 Box and use different Font .

Source code - A
import java.applet.Applet;
import java.awt.Color;
import java.awt.*;
public class NewApplet extends Applet {
public void init()
{
setBackground(Color.YELLOW);
setForeground(Color.RED);
}
public void paint(Graphics g)
{
g.setColor(Color.BLACK);
Font f1 = new Font("sanserif",Font.BOLD,12);
g.setFont(f1);
g.drawString("MY EXP_5 AKSHAY", 120, 20);
g.drawOval(40,40 ,130 ,180 );
g.drawOval(57, 75,30 ,20 );
g.drawOval(110,75 ,30 ,20 );
g.fillOval(68, 81, 10, 10);
g.fillOval(121, 81, 10, 10);
g.drawOval(85, 100, 30, 30);
g.setColor(Color.red);
g.fillArc(60,125,80,40,180,180);

g.drawOval(25, 92, 15, 30);


g.drawOval(170, 92, 15, 30);
} }

Source code - B
import java.applet.Applet;
import java.awt.*;
import java.awt.Graphics;
public class Box extends Applet {
public void init()
{
setBackground(Color.WHITE);
}
public void paint(Graphics g){
Font A = new Font ("sanserif",Font.BOLD,20);
Font B = new Font ("akshay",Font.ITALIC,20);
g.setFont(A);
g.setColor(Color.red);
g.drawString("THIS IS FIRST BOX",250,300);
g.setFont(B);
g.setColor(Color.BLACK);
g.drawString("THIS IS 2ND BOX",300,250);
g.drawString("THIS IS 3RD BOX",350,200);
g.drawString("THIS IS 4TH BOX",400,150);
g.drawRect(100,150,500,300);
g.drawRect(125,200,450,200);
g.drawRect(150,250,400,100);
g.drawRect(175,300,350,0) }
} )

Output
(A)

(B)

You might also like