import javax.swing.*;  
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import javax.swing.ImageIcon;
import javax.swing.JFrame;

class anchor extends JPanel implements ActionListener
{
	private FileMenu ankh= new FileMenu();
	int x, y, active=0, size=ankh.getTotalGames();
	KeypressControl keysensor = new KeypressControl(this);
	public static boolean buttons[] = new boolean [20];
	private Image[] sprite= new Image[size];
	private Image display;
	public boolean lip=true;
	Timer wait;
	
	private Image loadImage(String fileName) {
        return new ImageIcon(fileName).getImage();
    }

    public void drawImage(Graphics g, Image image, int x, int y,
        String caption)
    {
        g.drawImage(image, x, y, null);
    }
	public void paintComponent(Graphics g){
		//System.out.println(size);
		wait= new Timer(100, this);
		wait.start();
		super.paintComponent(g);
		for (int m=0; m<size; m++)
		{
			sprite[m] = loadImage("game"+(m+1)+"/black.jpg");
			g.drawImage(sprite[m], m, m*100, 100, 100, this);
		}
		display = loadImage("game"+(active+1)+"/colour.jpg");
		//sprite[0] = loadImage("pope.jpg");
		//sprite[1] = loadImage("player1.png");
		/*for (int m=0; m<size; m++)
		{
			g.drawImage(sprite[m], m, m*100, 100, 100, this);
			
		}
		*/
		g.drawImage(display, x, y, 100, 100, this);
		if(lip)	
			requestFocus();
	}
	
	public void actionPerformed(ActionEvent e){ 
		buttons = keysensor.getInput();
		wait.stop();
		//wait.reset ();
		if (buttons[11])
		{
			buttons[11]=false;
			active++;
			active=active%size;
			System.out.println(active);
		}
		else if (buttons[1])
		{
			buttons[1]=false;
			active--;
			if (active<0)
			active=active+size;
		}
		else if (buttons [0])
		{
			String temp="game"+(active+1)+"/";
			System.out.println(temp);
			runMain rm= new runMain(temp,"useGame");
			/*public Object invoke(Object useGame,
                     Object[0] args)
              throws IllegalAccessException,
                     IllegalArgumentException,
                     InvocationTargetException 
                     http://java.sun.com/j2se/1.4.2/docs/api/
                     */
			rm.go();
			lip=false;
		}
		y=active*100;
		repaint();
	}
}
