TerraSkilll 13 de nov. de 2012
guimarques1987
No seu código, arrayA é o array de String? Se possível, poste o código completo, porque só com esse trecho está difícil saber o que mexer.
Para checar se um checkbox está marcado o método é “isChecked”. Você o está usando?
Abraço.
guimarques1987 13 de nov. de 2012
if ( jCheckBox1 . isSelected ()) {
arrayA [ 0 ] = ( "UM" );
contador += 1 ;
} else {
arrayA [ 0 ] = ( "" );
}
if ( jCheckBox2 . isSelected ()) {
arrayA [ 1 ] = ( "DOIS" );
contador += 1 ;
} else {
arrayA [ 1 ] = ( "" );
}
if ( jCheckBox3 . isSelected ()) {
arrayA [ 2 ] = ( "TRES" );
contador += 1 ;
} else {
arrayA [ 2 ] = ( "" );
}
if ( jCheckBox4 . isSelected ()) {
arrayA [ 3 ] = ( "quatro" );
contador += 1 ;
} else {
arrayA [ 3 ] = ( "" );
}
if ( jCheckBox5 . isSelected ()) {
arrayA [ 4 ] = ( "cinco" );
contador += 1 ;
} else {
arrayA [ 4 ] = ( "" );
}
for ( int i = 0 ; i < arrayA . length ; i ++ ) {
// JLabel LinhaA = new JLabel ( arrayA [ i ] );
// if ( contador > 1 ) {
teste += arrayA [ i ] + "," + "\n" ;
// } else {
// teste += arrayA [ i ] + "\n" ;
// }
// painel . add ( LinhaA );
// LinhaA . setText ( "" );
// JOptionPane . showMessageDialog ( null , LinhaB );
}
jTextField1 . setText ( teste );
este comando é um teste que estou fazendo para depois colocar no trabalho fiinal
TerraSkilll 14 de nov. de 2012
Basta você checar, no for, se a string está preenchida:
for ( int i = 0 ; i < arrayA . length ; i ++ ) {
if ( ! arrayA [ i ] . equals ( "" )) // verifica se a posição do array não está vazia
teste += arrayA [ i ] + "," + "\n" ;
}
Mas, vendo seu código, você poderia preencher esta string teste já ao verificar os checkbox, eliminando a necessidade de usar o for:
String teste = "" ;
if ( JCheckBox1 .isSelected ())
teste += "UM," ;
if ( JCheckBox2 .isSelected ())
teste += "DOIS," ;
if ( JCheckBox2 .isSelected ())
teste += "TRES," ;
// e assim sucessivamente
Abraço.
guimarques1987 14 de nov. de 2012
muito obrigado TerraSkilll você me ajudou muito era exatamente oque eu queria.