package pmicrovenus;


import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.net.URL;
import java.util.Observable;
import java.util.Observer;
import javax.imageio.ImageIO;
import javax.swing.JPanel;


public class frmTablero extends javax.swing.JFrame implements Observer {
   	public static final int WIDTH = 610;
	public static final int HEIGHT = 610;
        
        Tablero CanvasTablero;
        Dado miDado;
        Jugador miPla;
   
   public frmTablero(Tablero inv, Dado dad, Jugador pla) {
      initComponents();
      
      CanvasTablero=inv;
      miDado=dad;
      miPla=pla;
      
      panel = (JPanel)this.getContentPane();
      //setBounds(0,0,WIDTH,HEIGHT);   
      //this.setBounds(0,0, 800, 633);
      panel.add(CanvasTablero);
      inv.setBounds(0,0,WIDTH,HEIGHT);
      inv.setVisible(true);
      this.setResizable(false);
   }
   
    // <editor-fold defaultstate="collapsed" desc=" Código Generado  ">//GEN-BEGIN:initComponents
    private void initComponents() {
        panel2 = new javax.swing.JPanel();
        jbtnTirarDado = new javax.swing.JButton();
        jlblValorCara = new javax.swing.JLabel();
        jlabel2 = new javax.swing.JLabel();
        jlblCasilla = new javax.swing.JLabel();
        panel = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jbtnTirarDado.setText("Tirar Dado");
        jbtnTirarDado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnTirarDadoActionPerformed(evt);
            }
        });

        jlabel2.setFont(new java.awt.Font("Tahoma", 1, 11));
        jlabel2.setText("Casilla:");

        org.jdesktop.layout.GroupLayout panel2Layout = new org.jdesktop.layout.GroupLayout(panel2);
        panel2.setLayout(panel2Layout);
        panel2Layout.setHorizontalGroup(
            panel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panel2Layout.createSequentialGroup()
                .addContainerGap()
                .add(panel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(panel2Layout.createSequentialGroup()
                        .add(jlabel2)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jlblValorCara, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 9, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jlblCasilla, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
                    .add(jbtnTirarDado))
                .addContainerGap())
        );
        panel2Layout.setVerticalGroup(
            panel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panel2Layout.createSequentialGroup()
                .addContainerGap()
                .add(jbtnTirarDado)
                .add(22, 22, 22)
                .add(panel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jlabel2)
                    .add(jlblValorCara, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(12, 12, 12)
                .add(jlblCasilla, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(513, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout panelLayout = new org.jdesktop.layout.GroupLayout(panel);
        panel.setLayout(panelLayout);
        panelLayout.setHorizontalGroup(
            panelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 684, Short.MAX_VALUE)
        );
        panelLayout.setVerticalGroup(
            panelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 610, Short.MAX_VALUE)
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .add(panel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(panel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
            .add(panel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbtnTirarDadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnTirarDadoActionPerformed
        int valor = miDado.tirar();
        Casilla c = miPla.getPosicion();
        miPla.setPosicion(CanvasTablero.mover(valor,c));
        jlblValorCara.setText(Integer.toString(miDado.getValorCara()));
        jlblCasilla.setText(miPla.getPosicion().getDescripcion());
    }//GEN-LAST:event_jbtnTirarDadoActionPerformed

    public void update(Observable o, Object arg) {
        CanvasTablero.repaint();
    }
   
   /**
    * @param args the command line arguments
    */
   
    // Declaración de varibales -no modificar//GEN-BEGIN:variables
    private javax.swing.JButton jbtnTirarDado;
    private javax.swing.JLabel jlabel2;
    private javax.swing.JLabel jlblCasilla;
    private javax.swing.JLabel jlblValorCara;
    private javax.swing.JPanel panel;
    private javax.swing.JPanel panel2;
    // Fin de declaración de variables//GEN-END:variables
   
}
