Wednesday, 10 July 2019

Published July 10, 2019 by with 0 comment

BCSL043 December 2015 Set 4 Solution




Question 1- Write a Java program to create an applet to draw a circle. Set background color of the circle as red. Also write your name and roll number below the circle.

Solution -

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

public class drawcircle extends Applet 
{
public void paint(Graphics g)
{
g.setColor(Color.red);
        g.fillOval(50,50,150,150);
        g.setColor(Color.black);
        g.drawString("Name = IGNOULIA",90,220);
        g.drawString("Roll No = FSJX3543",90,240);
}
}

/*
<applet code="drawcircle.class" width="330" height="300"></applet>
*/


filename: drawcircle.java
For compiling the file type this command in cmd: javac drawcircle.java
For execution of the file use this command: appletviewer drawcircle.java

Explanation:
setColor method of graphics object is used to set the color. fillOval(int x,int y,int width,int height) method is used to draw a oval,here x and y argument of fillOval() is used to specify the x and y coordinate of oval and length,width parameter is used to specifiy the width,height of oval.
Because here we are drawing a circle height,width parameter should be equal.

Output:


if you have any doubt related to this post, you can ask in comment section and if you want solution of any previous year questions, please post that question in section we will try to solve that

Thank You



0 comments:

Post a Comment