import javax.swing.JOptionPane;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 @author alex_2
 */
public class Tabellone extends javax.swing.JFrame {
    private TabelloneTennis a;
    /**
     * Creates new form Tabellone
     */
    public Tabellone() {
        initComponents();
        this.setTitle("Tabellone");
        new TabelloneTennis("Gepo","Piero");
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 new javax.swing.JPanel();
        lblUno new javax.swing.JLabel();
        lblDue new javax.swing.JLabel();
        btnUno new javax.swing.JButton();
        btnDue new javax.swing.JButton();
        lblVantaggi new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        lblUno.setFont(new java.awt.Font("Tahoma"0100)); // NOI18N
        lblUno.setText("0");

        lblDue.setFont(new java.awt.Font("Tahoma"0100)); // NOI18N
        lblDue.setText("0");

        btnUno.setText("Player one");
        btnUno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUnoActionPerformed(evt);
            }
        });

        btnDue.setText("Player two");
        btnDue.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDueActionPerformed(evt);
            }
        });

        lblVantaggi.setText("Vantaggi");

        javax.swing.GroupLayout jPanel1Layout new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(303030)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADINGfalse)
                    .addComponent(btnUnojavax.swing.GroupLayout.DEFAULT_SIZE134Short.MAX_VALUE)
                    .addComponent(lblUnojavax.swing.GroupLayout.DEFAULT_SIZEjavax.swing.GroupLayout.DEFAULT_SIZEShort.MAX_VALUE))
                .addGap(565656)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADINGfalse)
                    .addComponent(lblDuejavax.swing.GroupLayout.DEFAULT_SIZEjavax.swing.GroupLayout.DEFAULT_SIZEShort.MAX_VALUE)
                    .addComponent(btnDuejavax.swing.GroupLayout.DEFAULT_SIZE143Short.MAX_VALUE))
                .addContainerGap(37Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILINGjPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZEShort.MAX_VALUE)
                .addComponent(lblVantaggijavax.swing.GroupLayout.PREFERRED_SIZE185javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(128128128))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADINGfalse)
                    .addComponent(lblDuejavax.swing.GroupLayout.DEFAULT_SIZE204Short.MAX_VALUE)
                    .addComponent(lblUnojavax.swing.GroupLayout.DEFAULT_SIZEjavax.swing.GroupLayout.DEFAULT_SIZEShort.MAX_VALUE))
                .addGap(282828)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnUno)
                    .addComponent(btnDue))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblVantaggijavax.swing.GroupLayout.DEFAULT_SIZE17Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1javax.swing.GroupLayout.DEFAULT_SIZEjavax.swing.GroupLayout.DEFAULT_SIZEShort.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1javax.swing.GroupLayout.DEFAULT_SIZEjavax.swing.GroupLayout.DEFAULT_SIZEShort.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnUnoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUnoActionPerformed
        a.incrementaPunteggio(0);
        if (a.getSituazione() == 1)
        {
            JOptionPane.showMessageDialog(this"Ha vinto il giocatore 1");
            a.azzera();
            lblUno.setText(a.getPunteggio(0));
            lblDue.setText(a.getPunteggio(1));
            return;
        }
        if (Integer.parseInt(a.getPunteggio(0)) <= 40)
            lblUno.setText(a.getPunteggio(0));
        if (Integer.parseInt(a.getPunteggio(0)) - Integer.parseInt(a.getPunteggio(1)) == 100)
            lblVantaggi.setText("Vantaggio giocatore 1");
    if (Integer.parseInt(a.getPunteggio(0)) > 40 &&
            Integer.parseInt(a.getPunteggio(0)) == Integer.parseInt(a.getPunteggio(1)))
            lblVantaggi.setText("Vantaggio pari");
    }//GEN-LAST:event_btnUnoActionPerformed

    private void btnDueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDueActionPerformed
        a.incrementaPunteggio(1);
        if (a.getSituazione() == 2)
        {
            JOptionPane.showMessageDialog(this"Ha vinto il giocatore 2");
            a.azzera();
            lblUno.setText(a.getPunteggio(0));
            lblDue.setText(a.getPunteggio(1));
            return;
        }
        if (Integer.parseInt(a.getPunteggio(1)) <= 40)
            lblDue.setText(a.getPunteggio(1));
        if (Integer.parseInt(a.getPunteggio(1)) - Integer.parseInt(a.getPunteggio(0)) == 100)
            lblVantaggi.setText("Vantaggio giocatore 2");
    if (Integer.parseInt(a.getPunteggio(1)) > 40 &&
            Integer.parseInt(a.getPunteggio(0)) == Integer.parseInt(a.getPunteggio(1)))
            lblVantaggi.setText("Vantaggio pari");
    }//GEN-LAST:event_btnDueActionPerformed

    /**
     @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Tabellone.class.getName()).log(java.util.logging.Level.SEVEREnullex);
        catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Tabellone.class.getName()).log(java.util.logging.Level.SEVEREnullex);
        catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Tabellone.class.getName()).log(java.util.logging.Level.SEVEREnullex);
        catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Tabellone.class.getName()).log(java.util.logging.Level.SEVEREnullex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Tabellone().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnDue;
    private javax.swing.JButton btnUno;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lblDue;
    private javax.swing.JLabel lblUno;
    private javax.swing.JLabel lblVantaggi;
    // End of variables declaration//GEN-END:variables
}