import java.awt.Graphics;
import java.util.Scanner;
import javax.swing.JApplet;
public class Polygon extends JApplet{
public static void main (String[] args) {
int i,j;
int poly[]=new int[6];
System.out.println("Enter 3 pairs of coordinates for the polygon:");
Scanner scan = new Scanner (System.in);
for (i=0;i<poly.length;i++) {
poly[i]=scan.nextInt();
}
Polygon polygon = new Polygon();
poly.paint(g);
}
public void paint(Graphics g) {
g.drawLine(20, 20, 200, 200);
}
}
我正在尝试实例化我的paint方法,以便我可以使用用户输入的数组值作为g.drawLine()的坐标。当我尝试实例化这个方法时,我在poly.paint(g)中收到g的错误。任何人都可以就如何解决这个问题给我一些指导吗?
答案 0 :(得分:0)
Should be something like this
public void paint(Graphics g) {
g.drawLine(20, 20, 200, 200);
Polygon polygon = new Polygon();
poly.paint(g);
}
您在包含范围内使用g
的位置