Hi,
I suggest you to study following example of Rectangle class:
Code:
import java.awt.Graphics2D;
import java.awt.Rectangle;
public class RectangleTP extends JApplet {
final static BasicStroke stroke1 = new BasicStroke(2.0f);
public void init() {
setBackground(Color.blue);
setForeground(Color.blue);
}
public void paint(Graphics g) {
Graphics2D g02 = (Graphics2D) g;
g02.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g02.setPaint(Color.gray);
int x = 5;
int y = 7;
g02.setStroke(stroke);
g02.draw(new Rectangle2D.Double(x, y, 200, 200));
g02.drawString("Rectangle2D", x, 250);
}
public static void main(String sko[]) {
JFrame f1 = new JFrame("");
f1.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
} }
JApplet applet = new RectangleDemo2D();
f1.getContentPane().add("Center", applet);
f1.setSize(new Dimension(400, 300));
f1.show();
}
}
Bookmarks