-3

使使用 getPixel( 2, 3 ) 得到的像素用 setColor(java.awt.Color.Black) 变为黑色,然后用 show( ) 显示图片 提示:您必须声明并使用 Picture 引用变量,代码如下图片 p.

public static void main(String[] a)
{
    new Picture(FileChooser.pickAFile( );
}

这是我的答案,谁能告诉我这是否正确以及我是否需要进行任何更改?任何帮助,将不胜感激。另外,这不是一个硬件问题,我正在复习考试。因此,如果您要告诉我去做自己的事情,请不要费心回答。:)

public static void main(String[] a)
{
    Picture p = new Picture;
    new Picture(FileChooser.pickAFile( );
    Pixel pixRef;
    pixRef.getPixel(2,3);
    pixRef.setColor(java.awt.Color.Black);
    p.show();
}
4

2 回答 2

3

你会像这样考试不及格。

public static void main(String[] a)
{
  Picture p; // constructor is a method - but seems you instantiate it in next line
  p =new Picture(FileChooser.pickAFile( )); // assign it to p
  Pixel pixRef = new Pixel(); //avoid nullpointerexception! but logically you should get the pixel from the picture, which displayed in next line, can remove the "new Pixel()";
  pixRef = p.getPixel(2,3); // Shouldn't you get pixelref from picture?
  pixRef.setColor(java.awt.Color.Black);
  p.show(); // I don't understand this. Where do you show this? shouldn't you put it inside a Frame or something?
}
于 2013-05-17T03:46:14.420 回答
0
public static void main(String[] a)
{

Picture p = new Picture;  //what are you trying to call here?  you must try checking out how to create an object  it must be "Picture p = new Picture();" , and if you have just defined a parameterised constructor in Picture class and need an object of that directly do it this was
"Picture p = new Picture(FileChooser.pickAFile( ));

new Picture(FileChooser.pickAFile( )); // must be enclosed properly
Pixel pixRef;
pixRef.getPixel(2,3);  // must be initialized before using the instance methods "Pixel pixRef = new Pixel();"
pixRef.setColor(java.awt.Color.Black);
p.show();
}
于 2013-05-17T03:42:31.303 回答