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

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:

Program to display the rate of interest of banks by method overriding method

CODE: class bank { int getroi() { return 0; } } class SBI extends bank { int getroi() { return 8; } } class ICICI extends bank { int getroi() { return 7; } } class AXIS extends bank { int getroi() { return 9; } } class EXP17Q1 { public static void main(String args[]) { SBI s = new SBI(); ICICI i = new ICICI(); AXIS a = new AXIS(); System.out.println("SBI rate of interest: "+s.getroi()); System.out.println("ICICI rate of interest: "+i.getroi()); System.out.println("AXIS rate of interest: "+a.getroi()); } } OUTPUT:

Define an exception called ‘NotMatchexception’ that is thrown when a string is not equal to ‘India’. Write a java program that uses this exception.

Code: import java.util.Scanner; class NotMatchException extends Exception {   public NotMatchException (String str)   {     System.out.println(str);   } } public class StringExc {    public static void main(String[] args)    {      Scanner scan = new Scanner(System.in);      System.out.print("Enter the string : ");      String input = scan.nextLine();      try      {        if(input.equalsIgnoreCase("India"))          System.out.println("String matched !!!");        else          throw new NotMatchException ("String not matched !!!");     }     catch (NotMatchException s)     {     ...