Estoy haciendo un sencillo juego en java para practicar utilizando java swing.
El problema que tengo, es que, cuando selecciono una de las opciones (Piedra, papel o tijera), no muestra nada, y tendría que mostrar un mensaje diciendo, por ejemplo: "Usuario gana. Roca gana a Papel" o "Computadora gana. Tijeras gana a Papel".
Con la variable que tengo que se llama "rating", tendría que mostrar dichos textos, pero no lo hace.
Si alguien puede ayudarme o darme algún consejo será bienvenido
A continuación dejo el código:
Código
import java.awt.event.*; import javax.swing.*; import java.awt.Color; import java.awt.MouseInfo; import java.awt.Point; import com.sun.awt.AWTUtilities; import java.awt.geom.RoundRectangle2D; import java.awt.Shape; import java.util.concurrent.ThreadLocalRandom; /** * Declarando Variables */ private static final long serialVersionUID = 1L; private int x, y; /** * Piezas del Juego: Piedra, Papel y Tijera */ //private String actionPiedra = "piedra"; //private String actionPapel = "papel"; //private String actionTijera = "tijera"; // Generate a random action int random = ThreadLocalRandom.current().nextInt(0, 3); // Rate the current situation // Show a result alert }; /** * Creando la GUI */ private WindowPPT() { setUndecorated(true); initComponents(); setLocationRelativeTo(null); BarraMenu.setOpaque(true); BarraMenu.setFocusable(false); ExitButton.setFocusable(false); DownButton.setFocusable(false); Shape forma = new RoundRectangle2D.Double(0, 0, this.getBounds().width, this.getBounds().height, 30, 30); AWTUtilities.setWindowShape(this, forma); // Creando las Acciones de los Botones bPiedra.addActionListener(buttonListener); bPapel.addActionListener(buttonListener); bTijeras.addActionListener(buttonListener); } /** * Creando la Seleccion Random del Ordenador */ public static int computerRandomChoice() { return result; } @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jButton1ActionPerformed(evt); } }); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) ); BarraMenuMouseDragged(evt); } }); BarraMenuMousePressed(evt); } }); ExitButton.setText("X"); ExitButtonActionPerformed(evt); } }); DownButton.setText("_"); DownButtonActionPerformed(evt); } }); IconoLogo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/IcoLogo.jpg"))); // NOI18N jLabel1.setText("Evuy's Game"); javax.swing.GroupLayout BarraMenuLayout = new javax.swing.GroupLayout(BarraMenu); BarraMenu.setLayout(BarraMenuLayout); BarraMenuLayout.setHorizontalGroup( BarraMenuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, BarraMenuLayout.createSequentialGroup() .addComponent(IconoLogo) .addGap(18, 18, 18) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(DownButton, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(ExitButton, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)) ); BarraMenuLayout.setVerticalGroup( BarraMenuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(IconoLogo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(BarraMenuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(DownButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(ExitButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, BarraMenuLayout.createSequentialGroup() .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) ); bTijeras.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/Tijera_opt.png"))); // NOI18N bTijerasActionPerformed(evt); } }); bPapel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/Papel_opt.png"))); // NOI18N bPapelActionPerformed(evt); } }); bPiedra.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/Piedra_opt.png"))); // NOI18N bPiedraMouseClicked(evt); } }); bPiedraActionPerformed(evt); } }); javax.swing.GroupLayout FondoPantallaLayout = new javax.swing.GroupLayout(FondoPantalla); FondoPantalla.setLayout(FondoPantallaLayout); FondoPantallaLayout.setHorizontalGroup( FondoPantallaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(FondoPantallaLayout.createSequentialGroup() .addGap(25, 25, 25) .addComponent(bPiedra, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(52, 52, 52) .addComponent(bPapel, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(bTijeras, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(25, 25, 25)) ); FondoPantallaLayout.setVerticalGroup( FondoPantallaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(FondoPantallaLayout.createSequentialGroup() .addGap(88, 88, 88) .addGroup(FondoPantallaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(bTijeras, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(bPiedra, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(bPapel, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(BarraMenu, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(FondoPantalla, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(BarraMenu, 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(FondoPantalla, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) ); pack(); } x = evt.getX(); y = evt.getY(); } setLocation(point.x - x, point.y - y); } setExtendedState(ICONIFIED); } } try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { break; } } java.util.logging.Logger.getLogger(WindowPPT.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); java.util.logging.Logger.getLogger(WindowPPT.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); java.util.logging.Logger.getLogger(WindowPPT.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); java.util.logging.Logger.getLogger(WindowPPT.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } public void run() { new WindowPPT().setVisible(true); } }); } /** * Creando las Normas */ switch (userAction) { case "Piedra": switch (comAction) { case "Piedra": msg = "Empate. Ambos usaron Piedra!"; break; case "Papel": msg = "Has perdido. Papel gana a Piedra!"; break; case "Tijeras": msg = "Has ganado. Piedra gana a Tijeras!"; break; } break; case "Papel": switch (comAction) { case "Piedra": msg = "Has ganado. Papel gana a Piedra!"; break; case "Papel": msg = "Empate. Ambos usaron Papel!"; break; case "Tijeras": msg = "Has perdido. Tijeras gana a Papel!"; break; } break; case "Tijeras": switch (comAction) { case "Piedra": msg = "Has perdido. Piedra gana a Tijeras!"; break; case "Papel": msg = "Has ganado. Tijeras gana a Papel!"; break; case "Tijeras": msg = "Empate. Ambos usaron Tijeras!"; break; } break; } return msg; } // Variables declaration - do not modify // End of variables declaration }