循环复制图片

时间:2013-12-14 00:52:11

标签: java arrays image

我有六张照片需要复制到一个足够大的窗口,以免它们重叠而不会留下多余的空间。我正在迈出需要我编写showOff()的步骤。我的任务说实例化EditablePicture的操作是

EditablePicture bigshowPict = new EditablePicture(??,??);

我需要一个循环,将我的数组中的图片逐个复制到EditablePicture中

bigShowPict.copyIn(??,??,this.pictArray[??]);

其中循环计算一个或两个??,??找出复制图片的位置.EditablePicture类和bigShowPict方法是预定义的,不应该被更改。到目前为止,我的所有代码都是

House.java

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

  public House(String pString)
  {
    this.owner = pString;
  }
  public String toString()
  {
    return("The House owned by " + this.owner);
  }
  public void acquire( int i, Picture pRef )
  {
    this.pictArray[i] = 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()
  {
    int sum = 0;
    for (int i=0; i<7;i++)
    {
      sum = sum + this.pictArray[i].getWidth();
     int resultHeight=1000;
    int resultWidth = sum;
      bigShowPict.copyIn(resultWidth,resultHeight,this.pictArray[i]);
      EditablePicture bigShowPict = new EditablePicture(resultWidth,resultHeight);
      bigShowPict.show();
    }
  }
}

以及调用它们的应用 Test.java

import java.util.Scanner;
public class Test
{
  public static void main(String[] a)
  {
    House myHouse;
    myHouse = new House("Justin Chaisetseree");
    Scanner sc = new Scanner(System.in);
    FileChooser.pickMediaPath();
    for( int i = 0; i < 6; i++)
    {
      myHouse.acquire(i,new Picture(FileChooser.pickAFile()));
    }
    myHouse.printPictures();
    myHouse.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
      {
        myHouse.swap( userInput1, userInput2 );
      }
    }
    myHouse.showOff();      
  }
}

0 个答案:

没有答案