import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
public class DrawTest
{
public static void main(String[] args)
{
DrawFrame frame =new DrawFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
//构造结构
class DrawFrame extends JFrame
{
public DrawFrame()
{
setTitle("DrawTest");
setSize( DEFAULT_WIDTH,DEFAULT_HEIGHT );
DrawComponent component =new DrawComponent();
add(component);
}
public static final int DEFAULT_WIDTH=400;
public static final int DEFAULT_HEIGHT=400;
}
//画图形部分
class DrawComponent extends JComponent
{
public void paintComponent(Graphics g)
{
Graphics2D g2 =(Graphics2D)g;
//画坐标
g2.draw (new Line2D.Double(200,50,200,350));
g2.draw (new Line2D.Double(50,200,350,200));
g2.draw (new Line2D.Double(200,50,190,60));
g2.draw (new Line2D.Double(200,50,210,60));
g2.draw (new Line2D.Double(350,200,340,190));
g2.draw (new Line2D.Double(350,200,340,210));
//画抛物线
int x,y;
int m1=200;
int n1=200;
for(x=200;x<=400;x++)
{
y=200-(x-200)*(x-200);
g2.draw (new Line2D.Double(m1,n1,x,y));
m1=x;
n1=y;
}
int a1=200;
int b1=200;
for(x=200;x>=0;x--)
{
y=200-(x-200)*(x-200);
g2.draw (new Line2D.Double(a1,b1,x,y));
a1=x;
b1=y;
}
}
}