簡體   English   中英

如何實例化繪畫方法?

[英]How do I instantiate a paint method?

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);
  }
}

我正在嘗試實例化我的繪畫方法,以便可以使用用戶輸入的數組值作為g.drawLine()的坐標。 當我嘗試實例化此方法時,我在poly.paint(g)中的g上收到錯誤。 誰能給我一些有關如何解決此問題的指導?

Should be something like this


public void paint(Graphics g) {   
    g.drawLine(20, 20, 200, 200);

    Polygon polygon = new Polygon();
    poly.paint(g);
}

在包含范圍內使用g的位置

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM