我不得不使用java和canvas构建一个弹球风格的游戏来完成课程,但是我甚至无法画出圆圈,我得到了以下错误:“无法从静态上下文引用非静态方法fillCircle(int,int,int)”这是我目前拥有的代码,locations和diameter类以其他方式设置并完美地工作:
public void drawPinball1()
{
Canvas.fillCircle(currentXLocation, currentYLocation, getDiameter());
}发布于 2017-03-20 00:29:24
图形类的绘图方法
// Drawing (or printing) texts on the graphics screen:
drawString(String str, int xBaselineLeft, int yBaselineLeft);
// Drawing lines:
drawLine(int x1, int y1, int x2, int y2);
drawPolyline(int[] xPoints, int[] yPoints, int numPoint);
// Drawing primitive shapes:
drawRect(int xTopLeft, int yTopLeft, int width, int height);
drawOval(int xTopLeft, int yTopLeft, int width, int height);
drawArc(int xTopLeft, int yTopLeft, int width, int height, int startAngle, int arcAngle);
draw3DRect(int xTopLeft, int, yTopLeft, int width, int height, boolean raised);
drawRoundRect(int xTopLeft, int yTopLeft, int width, int height, int arcWidth, int arcHeight)
drawPolygon(int[] xPoints, int[] yPoints, int numPoint);
// Filling primitive shapes:
fillRect(int xTopLeft, int yTopLeft, int width, int height);
fillOval(int xTopLeft, int yTopLeft, int width, int height);
fillArc(int xTopLeft, int yTopLeft, int width, int height, int startAngle, int arcAngle);
fill3DRect(int xTopLeft, int, yTopLeft, int width, int height, boolean raised);
fillRoundRect(int xTopLeft, int yTopLeft, int width, int height, int arcWidth, int arcHeight)
fillPolygon(int[] xPoints, int[] yPoints, int numPoint);
// Drawing (or Displaying) images:
drawImage(Image img, int xTopLeft, int yTopLeft, ImageObserver obs); // draw image with its size
drawImage(Image img, int xTopLeft, int yTopLeft, int width, int height, ImageObserver o); // resize image on screen在本例中,您将使用drawOval(int xTopLeft, int yTopLeft, int width, int height);
this 教程可能会对你有所帮助。
参考:https://www.ntu.edu.sg/home/ehchua/programming/java/J4b_CustomGraphics.html
发布于 2017-03-20 00:09:22
创建一个画布对象,然后使用它。
Canvas canvas = new Canvas(300, 250);
GraphicsContext gc = canvas.getGraphicsContext2D();
gc.fillOval(10, 60, 30, 30);
gc.strokeOval(60, 60, 30, 30);https://stackoverflow.com/questions/42888754
复制相似问题