Sie sind auf Seite 1von 3

/*

* To change this template, choose Tools | Templates


* and open the template in the editor.
*/
/*
* EddieDice.java
*
* Created on 1/Jun/2010, 1:12:42
*/
package gui;
/**
*
* @author Billy Nero
*/
public class Dados extends java.awt.Frame {
/** Creates new form EddieDice */
public Dados() {
initComponents();
}
/** 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.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:i
nitComponents
private void initComponents() {
jButton1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
jButton1.setText("Lançar os dados!!!");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jLabel1.setText("Primeiro Dado");
jLabel2.setText("Segundo Dado");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addGroup(layout.createSequentialGroup()
.addGap(98, 98, 98)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE,
262, Short.MAX_VALUE)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SI
ZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE,
262, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE,
50, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(28, 28, 28)
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(jLabel2)
.addContainerGap(145, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exi
tForm
System.exit(0);
}//GEN-LAST:event_exitForm
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
FIRST:event_jButton1ActionPerformed
int dado1 = (int) (6*Math.random()+1); //lançar os dados para obter um valor entre
0.0 e 1.0,
int dado2 = (int) (6*Math.random()+1); //multiplica-lo por 6 e acrescentar 1 par
a termos resultados entre 1 e 6.
if (dado1==1) {jLabel1.setText("Primeiro Dado: 1");}//Consoante os valores aleatóri
os que foram
if (dado1==2) {jLabel1.setText("Primeiro Dado: 2");}//gerados, o botão muda o texto
dos labels.
if (dado1==3) {jLabel1.setText("Primeiro Dado: 3");}
if (dado1==4) {jLabel1.setText("Primeiro Dado: 4");}
if (dado1==5) {jLabel1.setText("Primeiro Dado: 5");}
if (dado1==6) {jLabel1.setText("Primeiro Dado: 6");}
if (dado2==1) {jLabel2.setText("Segundo Dado: 1");}
if (dado2==2) {jLabel2.setText("Segundo Dado: 2");}
if (dado2==3) {jLabel2.setText("Segundo Dado: 3");}
if (dado2==4) {jLabel2.setText("Segundo Dado: 4");}
if (dado2==5) {jLabel2.setText("Segundo Dado: 5");}
if (dado2==6) {jLabel2.setText("Segundo Dado: 6");}
}//GEN-LAST:event_jButton1ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Dados().setVisible(true);
}
});
}

// Variables declaration - do not modify//GEN-BEGIN:variables


public javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
// End of variables declaration//GEN-END:variables
}

Das könnte Ihnen auch gefallen