Solution of Handout-13

 

Solution of Problem#1:

 

import java.applet.Applet;

import java.awt.Graphics;

import java.awt.Graphics2D;

import java.awt.Rectangle;

import java.awt.geom.Ellipse2D;

import java.awt.geom.Line2D;

import java.awt.Color;

 

public class p2 extends Applet

{

            public void paint(Graphics g)

            {

                        Graphics2D g2 = (Graphics2D) g;

 

                        setBackground(Color.green);

 

                        Rectangle rectangle = new Rectangle(10,10,300,150);

                        Ellipse2D.Double Lcircle = new Ellipse2D.Double(10,10,150, 150);

                        Ellipse2D.Double Rcircle = new Ellipse2D.Double(159,10,150, 150);

                        g2.setColor(Color.blue);

                        g2.fill(rectangle);

 

                        g2.setColor(Color.yellow);

                        g2.fill(Lcircle);

 

                        g2.setColor(Color.yellow);

                        g2.fill(Rcircle);

 

                        g2.setColor(Color.red);

                        g2.drawString("Welcome to Aligarh Muslim University", 80, 90);

 

            }  // end of paint method

} // end of Applet class

 

Sample Output:

 

Solution of Problem#2:

import java.applet.Applet;

import java.awt.Graphics;

import java.awt.Graphics2D;

import java.awt.Rectangle;

import java.awt.geom.Ellipse2D;

import java.awt.geom.Line2D;

import java.awt.Color;

import java.awt.Font;

import javax.swing.JOptionPane;

import java.io.*;

 

public class p3 extends Applet

{

            Font font1;

            Font font2;

            Color myColor;

            Line2D.Double line;

            Rectangle rectangle;

            Ellipse2D.Double ellipse;

            String number1,number2,name;

            double sum;

public void init()

     {

        name=JOptionPane.showInputDialog("Please Enter your Course Name: ");

        number1 = JOptionPane.showInputDialog("Enter first Quiz Grades:");

        number2 = JOptionPane.showInputDialog("Enter second Quiz Grades:");

        double n1=Double.parseDouble(number1);

        double n2=Double.parseDouble(number2);

        sum=n1+n2;

 

                        myColor = new Color(0.0F, 0.0F, 0.0F);

                        font1 = new Font("Serif", Font.BOLD, 22);

                        font2 = new Font("SansSerif", Font.ITALIC, 15);

                        line = new Line2D.Double(10, 55, 550, 55);

                        rectangle = new Rectangle(10,70,300,200);

                        ellipse = new Ellipse2D.Double(20,80,280, 180);

  } // end of init method

 

public void paint(Graphics g)

    {

                        Graphics2D g2 = (Graphics2D) g;

                        setBackground(Color.cyan);

                        g2.setColor(Color.red);

                        g2.setFont(font1);

                        g2.drawString("Welcome to "+name, 10, 50);

                        g2.setColor(Color.red);

                        g2.draw(line);

                        g2.setColor(Color.blue);

                        g2.fill(rectangle);

                        g2.setColor(Color.yellow);

                        g2.fill(ellipse);

                        g2.setColor(myColor);

                        g2.setFont(font2);

                        g2.drawString("The sum of your Quiz Grades is :"+sum, 45, 180);

            }  // end of paint method

} // end of applet class