求助java2d 画曲线图?急!!!大神们帮忙~~~~

liuxiulong88 2013-01-25 08:43:42

谁能帮忙给一个上面图片的例子。代码~真的很着急啊,大婶们帮帮忙啊~~
...全文
106 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
liuxiulong88 2013-01-28
  • 打赏
  • 举报
回复
Planet X 2013-01-28
  • 打赏
  • 举报
回复
来拿分。。

package test;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;

import javax.swing.JFrame;


public class Test2D {
    
	private JFrame jf;
    private myCanvas cv;
	
    //构造函数
    public Test2D(){
        this.jf=new JFrame();
        this.cv=new myCanvas();
        jf.add(cv);
        jf.setSize(600,400);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jf.setVisible(true);  
    }
    
    /**
     * 函数逻辑,获取x轴点集合
     * @return
     */
    public int[] getX(){
    	//TODO
    	return null;
    }

    public int[] getY(){
    	//TODO
    	return null;
    }
    
    //测试
	public static void main(String[] args){
		Test2D test=new Test2D();	
		
		int[] x={50,100,150,200,250};
		int[] y={310,310-79,310-152,310-10,310-200};
		
		test.cv.setX(x);
		test.cv.setY(y);
		
	}
	
	//画布
	class myCanvas extends Canvas{
		private int x[];
		private int y[];  
		private int xPoint;
		private int yPoint;
		private int height;
		private int weight;

		public myCanvas(){
			
		}
		
		public void setX(int[] x) {
			this.x = x;
		}

		public void setY(int[] y) {
			this.y = y;
		}

		public myCanvas(int[] x,int[] y){
			this.x=x;
			this.y=y;
		}

		public void paint(Graphics g){
			Color c=new Color(255,255,255);
			g.setColor(c);
			//g.fillRect(xPoint,yPoint,height,weight);
			g.fillRect(50,10,450,300);
			
			//红线
			g.setColor(new Color(255,0,0));
			g.drawPolyline(x,y,5);
			
			//黑线
			g.setColor(new Color(0,0,0));
			//g.drawPolyline(x,y,5);
		}	
	}

}


51,396

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧