0% found this document useful (0 votes)
10 views

Programaciòn: Programa 1

The document contains code for two Java programs. Program 1 displays the elements of a list one by one in a text box by incrementing a counter variable. If the counter exceeds the size of the list, it displays an error message. Program 2 searches a list for a text string input by the user and displays the number of matches found. It uses a for loop to iterate through the list, compare each element to the search text, and increment a counter variable for each match.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Programaciòn: Programa 1

The document contains code for two Java programs. Program 1 displays the elements of a list one by one in a text box by incrementing a counter variable. If the counter exceeds the size of the list, it displays an error message. Program 2 searches a list for a text string input by the user and displays the number of matches found. It uses a for loop to iterate through the list, compare each element to the search text, and increment a counter variable for each match.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

PROGRAMACIN

ALUMNA: Cynthia Chipantiza

CURSO: Segundo Industrial B

PROGRAMA 1
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

ListModel aux;
aux=jMaquinas.getModel();

int ele;
ele=aux.getSize();

if(cuenta<ele){
Object obj;
obj=aux.getElementAt(cuenta);
String p;
jTexto.setText(obj.toString());
}
else{
jTexto.setText("EL ELEMENTO NO EXISTE");
}

++cuenta;

public static void main(String args[]) {

//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code


(optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look
and feel.
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(VentanaPrincipal.class.getName()).log(java.util.logg
ing.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(VentanaPrincipal.class.getName()).log(java.util.logg
ing.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(VentanaPrincipal.class.getName()).log(java.util.logg
ing.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(VentanaPrincipal.class.getName()).log(java.util.logg
ing.Level.SEVERE, null, ex);
}
//</editor-fold>
java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {


new VentanaPrincipal().setVisible(true);
}
});
}

// Variables declaration - do not modify


private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JList jMaquinas;
private javax.swing.JTextField jPosicion;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel jTexto;
// End of variables declaration
int cuenta=0;
}

CAPTURA DEPANTALLA

PROGRAMA2
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

//Obtener el texdto a buscar


String m;
m=jTexto.getText();

//Atraves de un ciclo for que empieca en 0 y termine en cantidad

int con=0;
ListModel mod;
mod=jApellidos.getModel();
int cuenta;
cuenta=mod.getSize();

for(int k=0;k<cuenta;++k){
Object o1;
o1=mod.getElementAt(k);

if(m.compareTo(o1.toString())==0){

++con;
}

}
jConteo.setText(m+"Existe"+String.valueOf(con)+"Veces");

CAPTURA DEPANTALLA

You might also like