Why is my array of images not showing up?
My program is supposed to come up and show 4 images, and then the user inputs which image they think doesn't belong. Depending on what they answer it simply replies "Right" or "Wrong"
The only problem that i am having is that the pictures are not coming up. Here is my code:
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class yea extends JFrame implements ActionListener{
ImageIcon[] ball = new ImageIcon[5];
Timer clock;
int frame;
Container p = this.getContentPane();
JLabel lblOutput = new JLabel("");
JTextField txtInput = new JTextField("Answer here: first, second, third, or fourth");
public static void main(String args[]){
new yea();
} // end main
public yea(){
super("Animate Images");
//load up the images
ball[1] = new ImageIcon("1.gif");
ball[2] = new ImageIcon("2.gif");
ball[3] = new ImageIcon("3.gif");
ball[4] = new ImageIcon("4.gif");
clock = new Timer(1000, this);
this.setVisible(true);
this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
p.setLayout(new BorderLayout());
this.init();
this.setVisible(true);
this.pack();
this.setSize(1270,1000);
clock.start();
} // end constructor
public void paint(Graphics g) {
super.paint(g);
g.drawImage(ball[frame].getImage(),300, 300, null);
} // end paint
public void init(){
Panel pNorth = new Panel();
pNorth.setLayout(new FlowLayout());
pNorth.add(new JLabel("Which Picture doesn't belong? first,second,third, or fourth?"));
Panel pSouth = new Panel();
pSouth.setLayout(new FlowLayout());
pSouth.add(lblOutput);
pSouth.add(txtInput);
p.add(pNorth, BorderLayout.NORTH);
p.add(pSouth, BorderLayout.SOUTH);
}
public void actionPerformed(ActionEvent e){
frame++;
if (frame > 4){
frame += 1;
String input = txtInput.getText();
if (input.equals("first")){
lblOutput.setText("yes!");
}
if(input.equals("second")) {
lblOutput.setText("No!");
}
if(input.equals("third")) {
lblOutput.setText("No!");
}
if(input.equals("fourth")){
lblOutput.setText("No!");
}
}
}
}