Ver Mensaje Individual
  #6 (permalink)  
Antiguo 13/03/2008, 00:53
Avatar de HackmanC
HackmanC
 
Fecha de Ingreso: enero-2008
Ubicación: Guatemala
Mensajes: 1.817
Antigüedad: 16 años, 3 meses
Puntos: 260
Sonrisa Re: Ayuda una variable

Creo que yo cambiaría esto :

Código:
        int var;
        double selection;
        double R = 1;
        double P = 2;
        double S = 3;
Por esto :

Código:
        int selection;
        int R = 1;
        int P = 2;
        int S = 3;
Y esto :

Código:
/*  Asking for input from the player and converting the entry into an Integer */

        selection = JOptionPane.showMessageDialog("Welcome to the Rock, Paper,
        Scissors"
        + "\nEnter 1 for ROCK" + "\nEnter 2 for PAPER" + "\nEnter 3 for SCISSORS");
        var = (int) selection;
Por esto :

Código:
        String s = "";
        Integer i = 0;
        while (i < 1 || i > 3) {
            try {
                s = JOptionPane.showInputDialog (null,
                                                 "Welcome to the Rock, Paper, Scissors" +
                                                 "\nEnter 1 for ROCK" +
                                                 "\nEnter 2 for PAPER" +
                                                 "\nEnter 3 for SCISSORS");
                if (s == null) System.exit(1);
                i = Integer.parseInt(s);
            } catch (NumberFormatException ex) {
                // showMessage (Hey.. ingrese un numero.)
            } catch (java.awt.HeadlessException ex) {
                // end with (Oops)
            }
        }
        selection = i;
Creo que si no quieres usar el modo gráfico por completo, con los botones,
sería mejor que no utilices showMessageDialog ni showInputDialog,
sino

System.out.println() y
{ Console console = System.console();
String inputline = console.readLine(...) }

Aunque puedo estar equivocado...
Saludos,

Última edición por HackmanC; 13/03/2008 a las 00:58