显示函数图像

 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;
       }
  

       

    }
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值