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:
PROGRAM
OUTPUT
C:\>javac DrawRectangles.java
C:\>appletviewer DrawRectangles.java
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
No comments:
Post a comment