
//Ejemplo manejo de etiquetas con imágenes

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;  //para incluir Random

public class Tomagochi2 extends JFrame
{
    int i,
	     j;  
	 
	 ImageIcon iconGoat = new ImageIcon("goat.jpg"); 
	 ImageIcon iconPiranna = new ImageIcon("piranna.jpg"); 
	 ImageIcon iconBarney = new ImageIcon("barney.jpg"); 
	 ImageIcon iconChupacabras = new ImageIcon("chupacabras.jpg"); 
    Random randomGenerator = new Random();
	 double randomValue;

	 
	 JLabel criaturas[][] = new JLabel[4][4]; 
	 JLabel lengthL, widthL,
           areaL, perimeterL;
    JTextField lengthTF, widthTF,
		           areaTF, perimeterTF;
    JButton calculateB, exitB;


    private static final int WIDTH = 400;
    private static final int HEIGHT = 300;

    public Tomagochi2()
    {
		        // Create four labels
         for (i=0; i <= 3; i++)
			{
			  for (j=0; j <= 3; j++)
			  {
			    criaturas[i][j] = new JLabel("Criatura",iconGoat,SwingConstants.RIGHT);
			  }
			}
			
			
		          //Set the title of the window
	      setTitle("Mega Tomagochi");

   
		          //Get the container
	      Container pane = getContentPane();

		          //Set the layout
        pane.setLayout(new GridLayout(4,4));

		          //Place all items created
        
		   for (i=0; i <= 3; i++)
			{
			  for (j=0; j <= 3; j++)
			  {
			    pane.add(criaturas[i][j]);
			  }
			}
			
			criaturas[1][1].setIcon(iconPiranna);
			criaturas[2][2].setIcon(iconBarney);
			randomValue = randomGenerator.nextDouble();
			if (randomValue < 0.25)
			{
				criaturas[3][3].setIcon(iconBarney);
			}
			else if (randomValue < 0.5)
			{
				criaturas[3][3].setIcon(iconPiranna);
			}
			else if (randomValue < 0.75)
			{
				criaturas[3][3].setIcon(iconGoat);
			}
			else
			{
				criaturas[3][3].setIcon(iconChupacabras);
			}	
 

		        //set the size of the window and display it
	      setSize(WIDTH,HEIGHT);
	      setVisible(true);
			  setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    public static void main( String args[] )
    {
	        Tomagochi2 rectObject = new Tomagochi2();
    }
}
