joguei na internet yatzi e resolvi imitar. to montando a interface.
ja desenvolvi um de memoria, mas nao entendo porque o mouselistener nao esta funcionando.
tambem peço algumas sugestoes, dicas, etc para o jogo ficar legal.
e se possivel como se faz protocolo tcp, ip para talvez jogar na internet com mais de um jogador.
valeu.
package yatzi_ou_general;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class General2 extends JFrame implements MouseListener {
ImageIcon Dado1 = new ImageIcon("C:/IMAGENS/dado1.gif");
ImageIcon Dado2 = new ImageIcon("C:/IMAGENS/dado2.gif");
ImageIcon Dado3 = new ImageIcon("C:/IMAGENS/dado3.gif");
ImageIcon Dado4 = new ImageIcon("C:/IMAGENS/dado4.gif");
ImageIcon Dado5 = new ImageIcon("C:/IMAGENS/dado5.gif");
ImageIcon Dado6 = new ImageIcon("C:/IMAGENS/dado6.gif");
ImageIcon Dado0 = new ImageIcon("C:/IMAGENS/dado0.gif");
JButton jbdado1 = new JButton("");
JButton jbdado2 = new JButton("");
JButton jbdado3 = new JButton("");
JButton jbdado4 = new JButton("");
JButton jbdado5 = new JButton("");
JButton jbdado6 = new JButton("");
JButton jbdado11 = new JButton("");
JButton jbdado22 = new JButton("");
JButton jbdado33 = new JButton("");
JButton jbdado44 = new JButton("");
JButton jbdado55 = new JButton("");
JButton jbdado66 = new JButton("");
public General2() {
initComponents();
JLabel contagem = new JLabel("contagem");
JLabel contagem1 = new JLabel("contagem");
JLabel bonus = new JLabel("bonus");
JLabel bonus1 = new JLabel("bonus");
JButton jbcontagem = new JButton("");
JButton jbcontagem1 = new JButton("");
JButton jbbonus = new JButton("");
JButton jbbonus1 = new JButton("");
JLabel num1 = new JLabel("1");
JLabel num2 = new JLabel("2");
JLabel num3 = new JLabel("3");
JLabel num4 = new JLabel("4");
JLabel num5 = new JLabel("5");
JLabel num6 = new JLabel("6");
JLabel jog1 = new JLabel("general");
JLabel jog2 = new JLabel("full house");
JLabel jog3 = new JLabel("trinca");
JLabel jog4 = new JLabel("dois pares");
JLabel jog5 = new JLabel("quadra");
JLabel jog6 = new JLabel("contagem");
JButton jbjog1 = new JButton("");
JButton jbjog2 = new JButton("");
JButton jbjog3 = new JButton("");
JButton jbjog4 = new JButton("");
JButton jbjog5 = new JButton("");
JButton jbjog6 = new JButton("");
JButton jbnum1 = new JButton("");
JButton jbnum2 = new JButton("");
JButton jbnum3 = new JButton("");
JButton jbnum4 = new JButton("");
JButton jbnum5 = new JButton("");
JButton jbnum6 = new JButton("");
jPanel2.setLayout(new GridLayout(16, 1));
jPanel2.add(num1);
jPanel2.add(jbnum1);
jPanel2.add(num2);
jPanel2.add(jbnum2);
jPanel2.add(num3);
jPanel2.add(jbnum3);
jPanel2.add(num4);
jPanel2.add(jbnum4);
jPanel2.add(num5);
jPanel2.add(jbnum5);
jPanel2.add(num6);
jPanel2.add(jbnum6);
jPanel2.add(bonus);
jPanel2.add(jbbonus);
jPanel2.add(contagem);
jPanel2.add(jbcontagem);
jPanel2.add(jog1);
jPanel2.add(jbjog1);
jPanel2.add(jog2);
jPanel2.add(jbjog2);
jPanel2.add(jog3);
jPanel2.add(jbjog3);
jPanel2.add(jog4);
jPanel2.add(jbjog4);
jPanel2.add(jog5);
jPanel2.add(jbjog5);
jPanel2.add(jog6);
jPanel2.add(jbjog6);
jPanel2.add(bonus1);
jPanel2.add(jbbonus1);
jPanel2.add(contagem1);
jPanel2.add(jbcontagem1);
//painel dos dados
jPanel6.setLayout(new GridLayout(3, 2));
jPanel6.add(jbdado1);
jPanel6.add(jbdado2);
jPanel6.add(jbdado3);
jPanel6.add(jbdado4);
jPanel6.add(jbdado5);
jPanel7.setLayout(new GridLayout(1, 5));
jPanel7.add(jbdado11);
jPanel7.add(jbdado22);
jPanel7.add(jbdado33);
jPanel7.add(jbdado44);
jPanel7.add(jbdado55);
jbdado1.setIcon(Dado1);
jbdado2.setIcon(Dado2);
jbdado3.setIcon(Dado3);
jbdado4.setIcon(Dado4);
jbdado5.setIcon(Dado5);
jbdado11.setIcon(Dado0);
jbdado22.setIcon(Dado0);
jbdado33.setIcon(Dado0);
jbdado44.setIcon(Dado0);
jbdado55.setIcon(Dado0);
}
public void mousePressed(MouseEvent e) {
if (e.getSource() == jbdado1) {
jbdado1.setIcon(Dado0);
}
}
public void mouseExited(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
if (e.getSource() == jbdado3) {
jbdado3.setBackground(Color.yellow);
}
}
public void mouseClicked(MouseEvent e) {
if (e.getSource() == jbdado2) {
jbdado2.setIcon(Dado0);
// jbdado11.setIcon(Dado1);
}
}
public void mouseReleased(MouseEvent e) {
}
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
jPanel3 = new javax.swing.JPanel();
jPanel4 = new javax.swing.JPanel();
jPanel5 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
jPanel6 = new javax.swing.JPanel();
jPanel7 = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(204, 0, 51)));
jPanel1.setForeground(new java.awt.Color(255, 0, 51));
jPanel1.setToolTipText("General em Java");
jPanel2.setBorder(javax.swing.BorderFactory.createMatteBorder(2, 2, 2, 2, new java.awt.Color(204, 0, 51)));
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 233, Short.MAX_VALUE)
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 327, Short.MAX_VALUE)
);
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 197, Short.MAX_VALUE)
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 323, Short.MAX_VALUE)
);
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 6, Short.MAX_VALUE)
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 331, Short.MAX_VALUE)
);
jPanel5.setBorder(javax.swing.BorderFactory.createMatteBorder(2, 2, 2, 2, new java.awt.Color(204, 0, 51)));
jButton1.setText("jogar");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
jPanel5.setLayout(jPanel5Layout);
jPanel5Layout.setHorizontalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
.addContainerGap(190, Short.MAX_VALUE)
.addComponent(jButton1))
);
jPanel5Layout.setVerticalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel5Layout.createSequentialGroup()
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel6.setBorder(javax.swing.BorderFactory.createMatteBorder(2, 2, 2, 2, new java.awt.Color(204, 0, 51)));
javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
jPanel6.setLayout(jPanel6Layout);
jPanel6Layout.setHorizontalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 253, Short.MAX_VALUE)
);
jPanel6Layout.setVerticalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 130, Short.MAX_VALUE)
);
javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
jPanel7.setLayout(jPanel7Layout);
jPanel7Layout.setHorizontalGroup(
jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 257, Short.MAX_VALUE)
);
jPanel7Layout.setVerticalGroup(
jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 80, Short.MAX_VALUE)
);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(17, 17, 17)
.addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(102, 102, 102))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
//joga o dado 1
double x = 0;
//cria o randomico
x = Math.random() * 6;
x = x + 1;
//converte para int
int b = (int) x;
String b11 = String.valueOf(b);
jbdado1.setIcon(Dado0);
if (b == 1) {
jbdado1.setText("");
jbdado1.setIcon(Dado1);
}
if (b == 2) {
jbdado1.setText("");
jbdado1.setIcon(Dado2);
}
if (b == 3) {
jbdado1.setText("");
jbdado1.setIcon(Dado3);
}
if (b == 4) {
jbdado1.setText("");
jbdado1.setIcon(Dado4);
}
if (b == 5) {
jbdado1.setText("");
jbdado1.setIcon(Dado5);
}
if (b == 6) {
jbdado1.setText("");
jbdado1.setIcon(Dado6);
}
//dado2
//joga o dado 1
x = 0;
//cria o randomico
x = Math.random() * 6;
x = x + 1;
//converte para int
b = (int) x;
b11 = String.valueOf(b);
jbdado2.setIcon(Dado0);
if (b == 1) {
jbdado2.setText("");
jbdado2.setIcon(Dado1);
}
if (b == 2) {
jbdado2.setText("");
jbdado2.setIcon(Dado2);
}
if (b == 3) {
jbdado2.setText("");
jbdado2.setIcon(Dado3);
}
if (b == 4) {
jbdado2.setText("");
jbdado2.setIcon(Dado4);
}
if (b == 5) {
jbdado2.setText("");
jbdado2.setIcon(Dado5);
}
if (b == 6) {
jbdado2.setText("");
jbdado2.setIcon(Dado6);
}
//dado3
//joga o dado 1
x = 0;
//cria o randomico
x = Math.random() * 6;
x = x + 1;
//converte para int
b = (int) x;
b11 = String.valueOf(b);
jbdado3.setIcon(Dado0);
if (b == 1) {
jbdado3.setText("");
jbdado3.setIcon(Dado1);
}
if (b == 2) {
jbdado3.setText("");
jbdado3.setIcon(Dado2);
}
if (b == 3) {
jbdado3.setText("");
jbdado3.setIcon(Dado3);
}
if (b == 4) {
jbdado3.setText("");
jbdado3.setIcon(Dado4);
}
if (b == 5) {
jbdado3.setText("");
jbdado3.setIcon(Dado5);
}
if (b == 6) {
jbdado3.setText("");
jbdado3.setIcon(Dado6);
}
//dado5
//joga o dado 1
x = 0;
//cria o randomico
x = Math.random() * 6;
x = x + 1;
//converte para int
b = (int) x;
b11 = String.valueOf(b);
jbdado4.setIcon(Dado0);
if (b == 1) {
jbdado4.setText("");
jbdado4.setIcon(Dado1);
}
if (b == 2) {
jbdado4.setText("");
jbdado4.setIcon(Dado2);
}
if (b == 3) {
jbdado4.setText("");
jbdado4.setIcon(Dado3);
}
if (b == 4) {
jbdado4.setText("");
jbdado4.setIcon(Dado4);
}
if (b == 5) {
jbdado4.setText("");
jbdado4.setIcon(Dado5);
}
if (b == 6) {
jbdado4.setText("");
jbdado4.setIcon(Dado6);
}
//dado6
//joga o dado 1
x = 0;
//cria o randomico
x = Math.random() * 6;
x = x + 1;
//converte para int
b = (int) x;
b11 = String.valueOf(b);
jbdado5.setIcon(Dado0);
if (b == 1) {
jbdado5.setText("");
jbdado5.setIcon(Dado1);
}
if (b == 2) {
jbdado5.setText("");
jbdado5.setIcon(Dado2);
}
if (b == 3) {
jbdado5.setText("");
jbdado5.setIcon(Dado3);
}
if (b == 4) {
jbdado5.setText("");
jbdado5.setIcon(Dado4);
}
if (b == 5) {
jbdado5.setText("");
jbdado5.setIcon(Dado5);
}
if (b == 6) {
jbdado5.setText("");
jbdado5.setIcon(Dado6);
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new General2().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel5;
private javax.swing.JPanel jPanel6;
private javax.swing.JPanel jPanel7;
// End of variables declaration
}