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

liuxiulong88 2013-01-25 08:43:42

谁能帮忙给一个上面图片的例子。代码~真的很着急啊,大婶们帮帮忙啊~~
...全文
75 2 点赞 打赏 收藏 举报
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
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);
		}	
	}

}


  • 打赏
  • 举报
回复
相关推荐
发帖
Java
加入

4.8w+

社区成员

Java相关技术讨论
申请成为版主
帖子事件
创建了帖子
2013-01-25 08:43
社区公告
暂无公告