-3

不断得到这些找不到符号错误。我知道它与图片类及其方法有关,但我知道它们在那里,但我的编译器无法识别它们。有任何想法吗?

     import java.awt.Color;
     import java.awt.Graphics;

     public class DispTest 
     { 

       private Picture display;
       private Graphics graphics;

       public DispTest()
       {
        display = new Picture(500,500);
        graphics = display.getGraphics();
        for(int x = 0; x < display.getWidth(); x++) {
           for(int y = 0; y < display.getHeight(); y++) {
             display.getPixel(x,y).setColor(new Color(123,204,246));
             if((x > 0 && x % 50 == 0) || (y > 0 && y % 50 == 0))
             display.getPixel(x,y).setColor(new Color(44,72,39));
           }
        }

        graphics.setColor(new Color(44,72,39));
          for(int x = 10; x < display.getWidth(); x += 50) 
             for(int y = 10; y < display.getHeight(); y += 50) 
                graphics.drawOval(x,y,30,30);
           display.show();
        }


        public static void main(String [] args)
        {
          DispTest dt = new DispTest();

        }
    }

发现 5 个错误:

File: C:\Users\Andrew\SoftwareDevelopment\DispTest.java  [line: 22]
Error: cannot find symbol
  symbol:   method getGraphics()
  location: variable display of type Picture
File: C:\Users\Andrew\SoftwareDevelopment\DispTest.java  [line: 25]
Error: cannot find symbol
  symbol:   method getPixel(int,int)
  location: variable display of type Picture
File: C:\Users\Andrew\SoftwareDevelopment\DispTest.java  [line: 27]
Error: cannot find symbol
  symbol:   method getPixel(int,int)
  location: variable display of type Picture
File: C:\Users\Andrew\SoftwareDevelopment\DispTest.java  [line: 32]
Error: cannot find symbol
  symbol:   method getWidth()
  location: variable display of type Picture
File: C:\Users\Andrew\SoftwareDevelopment\DispTest.java  [line: 33]
Error: cannot find symbol
  symbol:   method getHeight()
  location: variable display of type Picture
4

2 回答 2

1

Picture应该是Image类,import java.awt.Image;添加在你的类之上?在这种情况下,IDE(Eclipse、Netbeans)会为您提供帮助。

所以你可以拥有:

// import
import java.awt.Image;
import java.awt.image.BufferedImage;

...

// declaration
private Image display;

...

// instantiation, feel free to choose your third argument from http://docs.oracle.com/javase/6/docs/api/java/awt/image/BufferedImage.html
display = new BufferedImage(500, 500, BufferedImage.TYPE_INT_RGB);
于 2013-05-03T22:21:40.367 回答
0

删除您的.class文件并重新编译您的代码。当您的.class文件来自旧版本的源时,会发生此错误。

于 2013-05-03T22:21:21.900 回答