Olá, sou novo aqui no fórum.
Preciso fazer o jogo, pedra, papel, tesoura com interface gráfica.
São três jogador, então coloquei 3 comoBox e cada um com a opções pedra, papel, tesoura e depois tem um botão jogar para díspar a comparação.
Preciso fazer os ifs da vida e passar a mensagem para um textFiled ou um label com a mensagem empate ou jogador x é o vencedor.
O primeiro problema é que empaquei até na hora de consegui pegar a opção do jogar e passar para uma variável qualquer para depois fazer a comparação
String res1;
String res2;
String res3;
public void res(String res1, String res2, String res3){
this.res1 = res1;
this.res2 = res2;
this.res3 = res3;
}
@SuppressWarnings(“unchecked”)
// <editor-fold defaultstate=“collapsed” desc=“Generated Code”>
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
j2 = new javax.swing.JComboBox();
j1 = new javax.swing.JComboBox();
j3 = new javax.swing.JComboBox();
lPlacar = new javax.swing.JLabel();
jogar = new javax.swing.JButton();
res = new javax.swing.JTextField();
l1 = new javax.swing.JLabel();
l2 = new javax.swing.JLabel();
l3 = new javax.swing.JLabel();
private void jogarActionPerformed(java.awt.event.ActionEvent evt) {
res.setText(j1.getSelectedItem().toString());
res.setText(j2.getSelectedItem().toString());
res.setText(j3.getSelectedItem().toString());
/* assim não deu certo
res1 =((String)(j1.getSelectedItem()));
res2 =((String)(j2.getSelectedItem()));
res3 =((String)(j3.getSelectedItem()));*/
}
private void j1ActionPerformed(java.awt.event.ActionEvent evt) {
res1 =((String)(j1.getSelectedItem()));
}
private void j2ActionPerformed(java.awt.event.ActionEvent evt) {
res2 =((String)(j2.getSelectedItem()));
}
private void j3ActionPerformed(java.awt.event.ActionEvent evt) {
res3 =((String)(j3.getSelectedItem()));
}
// Variables declaration - do not modify
private javax.swing.JComboBox j1;
private javax.swing.JComboBox j2;
private javax.swing.JComboBox j3;
private javax.swing.JLabel jLabel1;
private javax.swing.JButton jogar;
private javax.swing.JLabel l1;
private javax.swing.JLabel l2;
private javax.swing.JLabel l3;
private javax.swing.JLabel lPlacar;
private javax.swing.JTextField res;
// End of variables declaration
}
