Java Prac 28

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Practical no.

28
 Develop a basic program to demonstrate applet.
/* <applet code=saee_applet.class width=500 height=500></applet>*/

importjava.applet.*;

public class saee_applet extends Applet

public void init()

System.out.println("Applet Initialized...");

public void start()

System.out.println("Applet Start...");

public void stop()

System.out.println("Applet Stop...");

public void destroy()

System.out.println("Applet Destroyed...");

}
}

Output:
C:\jdk1.7.0_80\bin>javac saee_applet.java

C:\jdk1.7.0_80\bin>appletviewer saee_applet.java

Applet Initialized...

Applet Start...

Applet Stop...

Applet Start...

Applet Stop...

Applet Destroyed...
 Develop a basic applet to display “Welcome to the world of
Applet”.
/* <applet code=saee_applet1.class width=500 height=500></applet>*/

importjava.applet.*;

importjava.awt.*;

public class saee_applet1 extends Applet

public void paint(Graphics g)

g.drawString("Welcome to the World of Applet", 50,100);

g.drawLine(200,200,300,300);

Output:
 Develop a program to implement drawRect() and fillRect() methods of
applet.
/* <applet code=saee_applet2.class width=500 height=500></applet>*/

importjava.applet.*;

importjava.awt.*;

public class saee_applet2 extends Applet

public void paint(Graphics g)

g.drawString("Rectangle", 10,10);

g.drawRect(20,20,70,50);

g.fillRect(100,20,70,50);

}
 Develop a program to implement drawRoundRect() and fillRoundRect()
methods of applet.

/* <applet code=saee_applet2.class width=500 height=500></applet>*/

importjava.applet.*;

importjava.awt.*;

public class saee_applet2 extends Applet

public void paint(Graphics g)

g.drawString("Rounded Rectangle", 10,10);

g.drawRoundRect(20,20,50,50,10,10);

g.fillRoundRect(90,20,50,50,10,10);

}
 Develop a program to implement drawOval() and fillOval() methods of
applet.

/* <applet code=saee_applet2.class width=500 height=500></applet>*/

importjava.applet.*;

importjava.awt.*;

public class saee_applet2 extends Applet

public void paint(Graphics g)

g.drawString("Oval", 10,10);

g.drawOval(20,20,50,70);

g.fillOval(80,20,50,70);

}
 Develop a program to implement drawArc() method of applet.

/* <applet code=saee_applet2.class width=500 height=500></applet>*/

importjava.applet.*;

importjava.awt.*;

public class saee_applet2 extends Applet

public void paint(Graphics g)

g.drawString("Arc", 270,270);

g.drawArc(250,250,50,50,180,180);

}
 Develop a program to implement drawPolygon() method of applet.

/* <applet code=saee_applet2.class width=500 height=500></applet>*/

importjava.applet.*;

importjava.awt.*;

public class saee_applet2 extends Applet

public void paint(Graphics g)

g.drawString("Polygon", 10,10);

g.setColor(Color.red);

int x1[]={10,170,80,10};

int y1[]={20,40,140,20};

int n=x1.length;

g.setColor(Color.red);

g.drawPolygon(x1,y1,n);

}
 Develop a program using control loops in applet.
/* <applet code=saee_applet2.class width=500 height=500></applet>*/

importjava.applet.*;

importjava.awt.*;

public class saee_applet2 extends Applet

public void paint(Graphics g)

g.drawString("Trafic Signal", 10,10);

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

if(i%2==0)

g.drawOval(120,i*60+10,50,50);

else

g.fillOval(120,i*60+10,50,50);

}
Output:

You might also like