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");
a = 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", 0, 100)); // NOI18N
lblUno.setText("0");
lblDue.setFont(new java.awt.Font("Tahoma", 0, 100)); // 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(30, 30, 30)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(btnUno, javax.swing.GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE)
.addComponent(lblUno, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(56, 56, 56)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(lblDue, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnDue, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE))
.addContainerGap(37, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(lblVantaggi, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(128, 128, 128))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(lblDue, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
.addComponent(lblUno, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(28, 28, 28)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnUno)
.addComponent(btnDue))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lblVantaggi, javax.swing.GroupLayout.DEFAULT_SIZE, 17, Short.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(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.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.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Tabellone.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Tabellone.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Tabellone.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</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
}