Program to draw Rectangles on Applet

This program demonstrates the methods of Graphics class. The drawRect( ) method draws the outline of the specified rectangle. The rectangle is drawn using the graphics context's current color. The syntax for drawRect( ) is given below:

void  drawRect (int x, int y, int width, int height)

The fillRect( ) method fills the specified rectangle. The rectangle is filled using the graphics context's current color. The syntax for fillRect( ) is given below:
void  fillRect (int x, int y, int width, int height)

The drawRoundRect( ) method draws an outlined round-cornered rectangle using the graphics context's current color. The syntax for drawRoundRect is given below:
void  drawRoundRect (int x, int y, int width, int height, int arcWidth, int arcHeight)

The fillRoundRect( ) method fills the specified rounded corner rectangle with the current color. The syntax for fillRoundRect( ) is given below:
void  fillRoundRect (int x, int y, int width, int height, int arcWidth, int arcHeight)


PROGRAM
// Draw rectangles
import java.awt.*;
import java.applet.*;

/*
<applet code="DrawRectangles" width=300 height=200>
</applet>
*/

public class DrawRectangles extends Applet 
{
 public void paint(Graphics g) 
 {
  g.drawRect(10, 10, 60, 50);
  g.fillRect(100, 10, 60, 50);
  g.drawRoundRect(190, 10, 60, 50, 35, 35);
  g.fillRoundRect(70, 90, 140, 100, 40, 40);
 }
}

OUTPUT 

C:\>javac DrawRectangles.java
C:\>appletviewer DrawRectangles.java



Popular posts from this blog

Program to define a class 'employee' with data members as empid, name and salary. Accept data for 5 objects using Array of objects and print it.

Define a class Student with four data members such as name, roll no.,sub1, and sub2. Define appropriate methods to initialize and display the values of data members. Also calculate total marks and percentage scored by student.

Program to input age from user and throw user-defined exception if entered age is negative