Split a query

0

I have a query from java a web services in c #, where I search all the data of a given id of a table and return it by means of a string to jtextfield, but I would like instead of showing the whole string in a single jtextfield will show me the data separately.

I tried it with the following code, but when pressing the button nothing happens and it does not mark me any errors.

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    int id=Integer.parseInt(jTextField1.getText());
    String cadena=consultaAlumno(id);
    String[] parts = cadena.split("-");
    String  jTextField2=parts[0];
    String  jTextField3=parts[1];
    String  jTextField4=parts[2];
    String  jTextField5=parts[3];
    String  jComboBox1=parts[4];
}                                        
    
asked by senseilex 30.11.2017 в 07:50
source

2 answers

0

If you do it in c #, doing so does not give any problem, but if you store it in Strings, you will not visually see any change in the graphic part:

String cadena="34-nombre-apellido-edad-dirección-telefono-sexo";
String[] parts = cadena.Split('-');
String  jTextField2=parts[0];  //Se mete 34
String  jTextField3=parts[1];  //Se mete nombre
String  jTextField4=parts[2];  //Se mete apellido
String  jTextField5=parts[3];  //Se mete edad
String  jComboBox1=parts[4];   //Se mete direccion

If you do it in java:

String cadena="34-nombre-apellido-edad-dirección-telefono-sexo";
String[] parts = cadena.split("-");
String  jTextField2=parts[0];
String  jTextField3=parts[1];
String  jTextField4=parts[2];
String  jTextField5=parts[3];
String  jComboBox1=parts[4];

This works in java but, as I said before, keep in mind that you are entering it in Strings, not objects of type Combobox or TextField. If you put a breakpoint you will see that if you split the chain.

    
answered by 30.11.2017 в 08:31
0

To add text to a textfield you have to use .setText()

jTextField2.setText(parts[0]);
jTextField3.setText(parts[1]);
jTextField4.setText(parts[2]);
jTextField5.setText(parts[3]);
    
answered by 30.11.2017 в 07:54