why the following code doesn't work?
it compiles but doesn't show anything on the applet.
import java.awt.*;
import java.applet.*;
import java.awt.geom.*; // Required for Rectangle2D
public class sample extends Applet
{
Graphics2D g2; // Reference to Graphics2D context
public sample() {} // Construct the applet
public void init() {} // Initialise the applet
// Applet screen paint method : use this to draw the rectangles.
public void paint(Graphics g)
{
// Cast the applet graphics contect to Graphics2D to allow us to
// draw Rectangle2D objects on it.
g2 = (Graphics2D) g;
// Small rectangle to show that the width and height are larger
// by one pixel than the specified parameters :
// x = 5, y = 5, width = 3, height = 2
Rectangle2D r0 = new Rectangle2D.Double(5,5,50,50);
// Three squares, each the same size, but one above each other.
// These are drawn with 1, 2, and 3 pixel wide borders to show how
// the border relates to the rectangle coordinates and position.
Rectangle2D r1 = new Rectangle2D.Double(15,10,50,50);
Rectangle2D r2 = new Rectangle2D.Double(25,20,50,50);
Rectangle2D r3 = new Rectangle2D.Double(35,30,50,50);
// Use a BasicStroke object to define various line widths, and
// draw these rectangles using these definitions.
BasicStroke s1 = new BasicStroke(2);
g2.setColor(Color.red);
g2.setStroke(s1); // Tell the graphics context about it
g2.draw(r0);
g2.draw(r1); // And ask it to draw the rectangle
g2.draw(r2);
g2.draw(r3);
}
}