I was giving task try to make a random image array with animals but I ran into a couple problems. First I try different types of array but I settle on string but I still don't know if it was the right one. The reason I went with strings is because I thought I could use getImage and use random generator for the number of the arrays. After clearing errors it still does not display a image. So can anyone point out what I'm missing here? Not important but I left GImage for ref.
import java.awt.*;
import java.util.*;
import acm.graphics.GImage;
import acm.program.GraphicsProgram;
import acm.util.RandomGenerator;
public class animalArray extends GraphicsProgram {
public void run(){
}
public void animalList(){
ArrayList<String> list = new ArrayList<String>();
String[] animal = new String[0]; {
animal[0] = "E:/JAVA/theTestingField/bear.png";
animal[1] = "E:/JAVA/theTestingField/bear.png";
animal[2] = "E:/JAVA/theTestingField/wolf.png";
animal[3] = "E:/JAVA/theTestingField/crow.png";
animal[4] = "E:/JAVA/theTestingField/cougar.png";
animal[5] = "E:/JAVA/theTestingField/bison.png";
animal[6] = "E:/JAVA/theTestingField/elk.png";
}
}
private void imageGen(){
r = (int) rgen.nextDouble(1, 6);
img = getImage(getCodeBase(), animal[r]);
}
public void paint(Graphics g){
g.drawImage(img, 0, 0, this);
}
private RandomGenerator rgen = RandomGenerator.getInstance();
private int r;
String[] animal;
GImage bear = new GImage("E:/JAVA/theTestingField/bear.png");
GImage wolf = new GImage("E:/JAVA/theTestingField/wolf.png");
GImage crow= new GImage("E:/JAVA/theTestingField/crow.png");
GImage cougar = new GImage("E:/JAVA/theTestingField/cougar.png");
GImage bison = new GImage("E:/JAVA/theTestingField/bison.png");
GImage elk = new GImage("E:/JAVA/theTestingField/elk.png");
Image img;
}
Aucun commentaire:
Enregistrer un commentaire