我正在創建一個程序,我可以使用直接從國家氣象服務網站獲取的數據繪製特定城市的最高日溫度。我有數據,但是當我嘗試創建實際圖形時出現程序錯誤。我的錯誤說我需要返回類型,但如果你看我的代碼,我有一個。它的OOP格式,所以我會告訴你的代碼是實現類的一部分。有人能告訴我如何解決我的錯誤?來自網站的圖表數據
我的錯誤:
invalid method declaration; return type required
我的代碼:
public class createGraph
{
Picture canvas = null;
Graphics g = null;
Graphics2D g2 = null;
DrawingGraph(int length, int height, Color color)
{
canvas = new Picture(length, height);
canvas.setAllPixelsToAColor(color);
g = canvas.getGraphics();
g2 = (Graphics2D)g;
g2.setColor(color);
}
public void drawARectangle(Color color, int x1, int y1, int width, int height)
{
g2.setColor(color);
g2.drawRect(x1, y1, width, height);
}
public Picture getGraph()
{
return canvas;
}
g.drawString("Maximum Temperature Readings", 196, 65);
g.drawString("Pensacola, FL - August, 2009", 205, 80);
int xPos = 97;
for(int day = 1; day <= 31; day++)
{
xPos = xPos + 13;
g.drawLine(xPos, 500, xPos, 510);
}
for(int yPos = 100; yPos <= 500; yPos +=40)
{
g.drawLine(93,yPos, 100, yPos);
}
g.drawString("100", 70, 105);
g.drawString("90", 75, 145);
g.drawString("80", 75, 185);
g.drawString("70", 75, 225);
}
最終圖表應該結束這樣看: