Foros del Web » Programación para mayores de 30 ;) » Java »

change type of "variable" to Object

Estas en el tema de change type of "variable" to Object en el foro de Java en Foros del Web. ... Código: package mycolorscode; import javax.swing.*; /** * * @author Edison Jair Lizcano */ public class Main { public static void main(String[] args) { String ...
  #1 (permalink)  
Antiguo 07/11/2008, 15:18
Avatar de JairLizcano  
Fecha de Ingreso: junio-2008
Ubicación: Santander, Colombia
Mensajes: 608
Antigüedad: 15 años, 10 meses
Puntos: 53
Exclamación change type of "variable" to Object

...
Código:
package mycolorscode;
import javax.swing.*;
/**
 *
 * @author Edison Jair Lizcano
 */
public class Main {

    public static void main(String[] args) {
   
        
        
        String [] valores = {"Negro", "Marron", "Rojo", "Naranja"};
         String ventana = JOptionPane.showInputDialog(null,"Primera franja",
                                                                "Valores resistivos - freeware", 
                              JOptionPane.PLAIN_MESSAGE,null,valores,valores[0]);
        int franja1=0;
        if(ventana==valores[0]){
            franja1=10;
        }
      
       
    }

}
...para el anterior codigo en la zona que resalto, me indica, que cambie el tipo String a Object, ahora con esto funciona sin problemas...pero...

...por que Object?...por que no String?...
  #2 (permalink)  
Antiguo 07/11/2008, 16:16
 
Fecha de Ingreso: septiembre-2008
Ubicación: Córdoba
Mensajes: 67
Antigüedad: 15 años, 7 meses
Puntos: 0
Respuesta: change type of "variable" to Object

Según la api de java

static String showInputDialog(Component parentComponent, Object message)
Shows a question-message dialog requesting input from the user parented to parentComponent.

static String showInputDialog(Component parentComponent, Object message, Object initialSelectionValue)
Shows a question-message dialog requesting input from the user and parented to parentComponent.

static String showInputDialog(Component parentComponent, Object message, String title, int messageType)
Shows a dialog requesting input from the user parented to parentComponent with the dialog having the title title and message type messageType.

static Object showInputDialog(Component parentComponent, Object message, String title, int messageType, Icon icon, Object[] selectionValues, Object initialSelectionValue)
Prompts the user for input in a blocking dialog where the initial selection, possible selections, and all other options can be specified.


static String showInputDialog(Object message)
Shows a question-message dialog requesting input from the user.

static String showInputDialog(Object message, Object initialSelectionValue)
Shows a question-message dialog requesting input from the user, with the input value initialized to initialSelectionValue.

Por lo visto te muestra unas opciones, pues esas opciones son objects (que pueden o no ser Strings), por lo tanto al seleccionar, te devolvera un object, o sea el objeto seleccionado.

Es lo que deduzco...

Saludos
  #3 (permalink)  
Antiguo 08/11/2008, 13:08
Avatar de JairLizcano  
Fecha de Ingreso: junio-2008
Ubicación: Santander, Colombia
Mensajes: 608
Antigüedad: 15 años, 10 meses
Puntos: 53
Respuesta: change type of "variable" to Object

...entiendo, pero..."pueden o no ser String"?, llegue a la conclusion que son estrictamente no String.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 10:43.