在数组中显示图片

时间:2013-12-13 21:11:24

标签: java arrays image

在drjava中我试图获取图片,将它们保存在阵列中,然后打印出每张图片的描述。现在一切都编译但是当我运行它时,我选择包含图片的文件夹,然后交互窗格消失。我到目前为止的代码是在我的House应用程序中获取图片和打印描述

SSCCEE

HOUSE.java

public class House
{
  String owner;
  public final static int CAPACITY = 6;
  Picture[ ] pictArray = new Picture[CAPACITY];

  public House(String pString)
  {
    this.owner = pString;
  }
  public String toString()
  {
    return("The House owned by " + this.owner);
  }
  public void acquire( int position, Picture pRef )
  {
    this.pictArray[ position ] = pRef;
  }
  public void printPictures()
  {
    for (int i=0; i < this.pictArray.length;i++)
    {
      System.out.print("The Picture in position " + i + " is ");
      System.out.println( this.pictArray[ i ]);
    }
  }
  public void swap( int positionA, int positionB )
  {
    System.out.println("NOTHING DONE.  THIS IS JUST A swap's STUB");

  }
  public void showOff()
  {
    System.out.println("NOTHING DONE.  THIS IS JUST showOff's STUB");

  }
}

Test.java

import java.util.Scanner;
public class Test
{
  public static void main(String[] a)
  {
    House h = new House("Justin Chaisetseree");
    Scanner sc = new Scanner(System.in);
    FileChooser.pickMediaPath();
    for( int i = 0; i < 6; i++)
    {
      h.acquire(i,new Picture(FileChooser.pickAFile()));
    }
    h.printPictures();
    h.showOff();
    Boolean done = false;
    while( ! done )
    {
      System.out.println("Which two do you want to swap?");
      System.out.print("Type in two numbers from 0 to ");
      System.out.print( 5 );
      System.out.println(" or two -1s to stop.");
      int userInput1 = sc.nextInt();
      int userInput2 = sc.nextInt();
      if( userInput1 < 0 || userInput2 < 0)
      {
        done = true;
      }
      else
      {
        h.swap( userInput1, userInput2 );
      }
    }
    h.showOff();      
  }
}

0 个答案:

没有答案