日期:2014-05-20 浏览次数:20709 次
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);
}
}
}