 |
|
|
BasicTest.java
|
/*
* Author: Havard Rast Blok
* E-mail: 
* Web : www.rememberjava.com
*/
import java.awt.*;
import javax.swing.*;
/*
* Draws a point, polygon and rectangle
*/
public class BasicTest extends JFrame
{
Point point;
Polygon polygon;
Rectangle rectangle;
int xpoints[] = {100, 150, 170, 160, 130};
int ypoints[] = {100, 80, 120, 150, 160};
public BasicTest()
{
super("Geometry");
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
setSize(300, 300);
//init shapes
point = new Point( 50, 50 );
polygon = new Polygon( xpoints, ypoints, xpoints.length );
rectangle = new Rectangle( 200, 200, 50, 50 );
show();
}
public void paint( Graphics g )
{
//draw the objects based on the contained values
g.drawLine( point.x, point.y, point.x, point.y );
g.fillPolygon( polygon );
g.drawRect( rectangle.x, rectangle.y, rectangle.width, rectangle.height );
}
public static void main(String args[])
{
new BasicTest();
}
}
|
|
|
 |