Skip to main content

Develop a program to draw any one of the following: a) Square inside a circle b) Circle inside a square


a.  Square inside a circle

/*<applet code="Square.class" width=300 height=300>
</applet>
*/
import java.applet.*;
import java.awt.*;
public class Square extends Applet
{
public void paint(Graphics g)
{
g.drawString("Square inside a circle",150,115);
g.drawOval(180,10,80,80);
g.drawRect(192,22,55,55);
}
}
OUTPUT:



b.  Circle inside a square

/*<applet code="Circle.class" width=300 height=300>
</applet>
*/
import java.applet.*;
import java.awt.*;
public class Circle extends Applet
{
public void paint(Graphics g)
{
g.drawString("Circle inside a square",65,115);
g.drawRect(80,10,80,80);
g.drawOval(80,10,80,80);
}
}
OUTPUT:




Comments

Popular posts from this blog

Program to calculate the room area and volume to illustrate the concept of single inheritance.

CODE: class Roomarea   { protected double l, b; Roomarea(double len, double br) { l=len; b=br; } void putdata() { System.out.println("Area of Room: "+(l*b)); } } class Roomvol extends Roomarea   { double h; Roomvol(double len, double br, double he) { super(len, br); h=he;   } void putdata() { super.putdata(); System.out.println("Volume of Room: "+(l*b*h)); } } public class EXP18Q4 { public static void main(String[] args) { Roomvol r1 = new Roomvol(10, 20, 10); r1.putdata();   } }

Develop a program to accept a Password from the user and throw “Authentication Failure” exception if the password is incorrect

import java.util.*; class Test {   public static void main(String args[])   {     try     {       System.out.println("Enter Password: ");       Scanner obj=new Scanner(System.in);       String pass= obj.nextLine();       if(!pass.equals("1234"))          System.out.println("Authentication Failure");       else          System.out.println("Welcome....!!");      }      catch (Exception e)      {        System.out.println("");      }      finally      {        System.out.println("Thank You.........!!!!!");    ...

Develop a program using control loops in applets.

Code: import java.awt.*; import java.applet.*; public class Control extends Applet {      public void paint(Graphics g)      {      for(int i=1;i<=4;i++)     {          if(i%2==0)         {            g.fillOval(90,i*50+10,50,50);           g.setColor(Color.black);        }        else       {          g.fillOval(90,i*50+10,50,50);          g.setColor(Color.red);       }    }   } } /* <applet code=Control width=300 height=300> </applet> */ Output: