我正在尝试在方法中设置图片setFavoritePicture (Picture pRef)
。此方法应该设置要在 main 方法中调用的最喜欢的图片,但我一直收到编译器错误说nonstatic variable pRef cannot be referenced from a static context
。我对 java 比较陌生,所以您可以为我提供的任何帮助将不胜感激
public class House
{
String owner;
Picture pRef;
Picture [] picArray;
Picture favPic;
public void showArtCollection ()
{
ArtWall aWall = new ArtWall(600,600);
aWall.copyPictureIntoWhere(favPic,250,100);
aWall.copyPictureIntoWhere(picArray[0],51,330);
aWall.copyPictureIntoWhere(picArray[1],151,330);
aWall.copyPictureIntoWhere(picArray[2],351,280);
aWall.show();
}
public House (String param)
{
this.owner = param;
this.picArray = new Picture [3];
this.favPic = new Picture (FileChooser.pickAFile ());
this.picArray [0] = new Picture (FileChooser.pickAFile ());
this.picArray [1] = new Picture (FileChooser.pickAFile ());
this.picArray [2] = new Picture (FileChooser.pickAFile ());
}
public void setFavoritePicture (Picture pRef)
{
pRef = favPic;
}
public void setOneOtherPicture (int which,Picture pRef)
{
}
public void swapGivenOtherWithFavorite (int which)
{
Picture tempSaver;
tempSaver = pRef;
pRef = picArray [which];
picArray [which] = tempSaver;
}
public void addPicture (Picture pictureAdded)
{
pRef = pictureAdded;
}
public void showPicture ()
{
picArray [0].explore ();
picArray [1].explore ();
picArray [2].explore ();
favPic.explore ();
}
public static void main (String [] args)
{
House PhDsHouse = new House ("Mad PH.D.");
PhDsHouse.setFavoritePicture (pRef);
PhDsHouse.swapGivenOtherWithFavorite (2);
PhDsHouse.showArtCollection ();
}
}