Program to draw Smiley in Applet

This Java example shows how to draw smiley in an applet window using Java Applet class methods.

import java.applet.Applet;
import java.awt.*;

public class SmileyExc extends Applet {

 public void paint(Graphics g) {
  g.fillOval(20,20,150,150);   // For face
  g.fillOval(50,60,15,25);     // Left Eye 
  g.fillOval(120,60,15,25);    // Right Eye
  int x[] = {95,85,106,95};
  int y[] = {85,104,104,85};
  g.drawPolygon(x, y, 4);      // Nose
  g.drawArc(55,95,78,50,0,-180);  // Smile
  g.drawLine(50,126,60,116);   // Smile arc1
  g.drawLine(128,115,139,126);  // Smile arc2

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



Popular posts from this blog

Program to define a class 'employee' with data members as empid, name and salary. Accept data for 5 objects using Array of objects and print it.

Define a class Student with four data members such as name, roll no.,sub1, and sub2. Define appropriate methods to initialize and display the values of data members. Also calculate total marks and percentage scored by student.

Program to input age from user and throw user-defined exception if entered age is negative