Skip to main content

Posts

Showing posts from April, 2019

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)     {     ...

Develop a basic applet to display welcome to the world of

Code: import java.applet.*; import java.awt.*; /*<applet code="Hello" width=400 height=400> </applet>*/ public class Hello extends Applet {    public void paint(Graphics g)   {       g.drawString("Welcome to the World of Applet !", 100, 100);   } } Output:

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:

Develop a program to draw a polygon.

Code: Import java.applet.*; importjava.awt.*; public class Draw extends java.applet.Applet { intxCoords[] = { 50, 200, 300, 150, 50, 50 }; intyCoords[] = { 100, 0, 50, 300, 200, 100 }; public void paint(Graphics g) { g.drawString("Polygon",50,50); g.drawPolygon(xCoords, yCoords, 6); } } /* <applet code=Draw width=300 height=300> </applet> */ Output:

Develop an applet for drawing a human face.

Code: import java.awt.*; importjava.applet.*; /* <applet code = "face" width = 300 height = 300></applet> */ public class face extends Applet {     public void paint(Graphics g)     { g.drawOval(40, 40, 120, 150); 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.fillArc(60, 125, 80, 40, 180, 180); g.drawOval(25, 92, 15, 30); g.drawOval(160, 92, 15, 30);     } } Output:

Write the output of the program.

Code: importjava.applet.*; importjava.awt.*; /* <applet code="Arcs" width=300 height=300> </applet> */ public class Arcs extends Applet { public void paint(Graphics g) { g.drawArc(10,40,70,70,0,75); g.fillArc(100,40,70,70,0,75); g.drawArc(10,100,70,80,0,175); g.fillArc(100,100,70,90,0,270); g.drawArc(200,80,80,80,0,180); } } OUTPUT:

Write output of program.

Code: /* <applet code="SetBackgroundColorExample.class" width=200 height=200> </applet> */ import java.applet.Applet; import java.awt.*; public class SetBackgroundColorExample extends Applet { public void paint(Graphics g) { /* *Set background color of an applet using *void SetBackground(Color c)method */ setBackground(Color.red); } }

Develop a program to draw any 2 of the following shapes: a) Cone b) Cylinder c) Cube

a.   Cone import java.applet.*; import java.awt.*; public class Cone extends Applet { public void paint(Graphics g) { g.drawOval(80,280,320,100); g.drawLine(240,50,82,320); g.drawLine(240,50,398,320); g.drawLine(240,330,398,330); g.drawLine(240,50,240,330); g.drawString("Radius",260,360); g.drawString("Height",246,255); g.drawString("Slant Height",340,210); g.drawString("Cone",220,420); } } /* <applet code="Cone.class" height=500 width=700> </applet> */ b.       Cylinder import java.applet.*; import java.awt.*; public class Cylinder extends Applet { public void paint(Graphics g) { g.drawString("Cylinder",80,50); g.drawOval(50,60,100,50); g.drawLine(50,80,50,200); g.drawLine(150,80,150,200); g.drawOval(50,180,100,50); } } /* <applet code="Cylinder.class" width=300 height=300> </applet...

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: