读书人

java2d 画曲线图?大神们帮忙~

发布时间: 2013-02-19 11:11:40 作者: rapoo

求助java2d 画曲线图?急!!!大神们帮忙~~~~
java2d 画曲线图?大神们帮忙~
谁能帮忙给一个上面图片的例子。代码~真的很着急啊,大婶们帮帮忙啊~~ java2D 曲线图
[解决办法]

来拿分。。



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相关

热点推荐