如何繪製x,y點的一條線?我嘗試使用圖形2D,但我得到的錯誤「類型Graphics中的方法drawLine(int,int,int,int)不適用於參數(double,double,double,double)」。如果我不使用Graphics 2D,如何在java中繪製線條?如何在java中繪製x,y點的線,其中x和y是雙精度型?
public void paint(Graphics g){
float []data= Series.getY();
double x1 = 0;
double y1 = 0;
for (int i = 0; i < data.length; i++){
double x2 = i;
double y2 = data[i];
g.drawLine(x1, y1, x2, y2);
y1 = y2;
x1 = x2;
}
}
我已經試過這
public class PlotPanel {
public void paint (Graphics g) {
float []data= Series.getY();
Graphics2D g2 = (Graphics2D) g;
double y1 = 0;
double x1 = 0;
for (int i = 0; i < data.length; i++){
double x2 = i;
double y2 = data[i];
g2.draw(new Line2D.Double(x1, y1, x2, y2));
y1 = y2;
x1 = x2;
}
}
public static void main(String args[]) {
PlotPanel pp = new PlotPanel();
pp.paint(g2);
}
}
它說G2不能被解析爲一個變量。我如何檢查它是否有效?
請編輯您的帖子以顯示您在標籤中使用的編程語言。 –