How to Draw 3-D Rectangles and Squares in Java


This example demonstrates how to draw 3-D rectangles and squares in an applet window with draw3DRect method of Graphics class. It also demonstrates how to draw a filled 3-D rectangles and squares.

Source Code

package com.beginner.examples;

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
 
public class DrawExample1 extends Applet{
 
	public void paint(Graphics g){
		
		g.setColor(Color.green);
		// draw rectangle
		g.draw3DRect(10 , 20 , 50 , 120 , true);
		System.out.println("ok");
	}
}

Output:

ok

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments