public class CONTADORDEVOCALES extends javax.swing.JFrame {
void aceptar(){
String texto;
int x;
texto=txtCuenta.getText();
int cuentavocales=0;
for(x=0; x<texto.length();x++){
if((texto.charAt(x)=='a')||
(texto.charAt(x)=='e')||
(texto.charAt(x)=='i')||
(texto.charAt(x)=='o')||
(texto.charAt(x)=='u')){
cuentavocales++;
}
}
lblRespuesta.setText("El texto" +"'"+texto+"'"+"contiene" +cuentavocales+ "vocales");
}
void limpiar (){
txtCuenta.setText("");
lblRespuesta.setText("");
public CONTADORDEVOCALES() {
initComponents();
}
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
txtCuenta = new javax.swing.JTextField();
btnAceptar = new javax.swing.JButton();
btnNuevo = new javax.swing.JButton();
lblRespuesta = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
jLabel1.setForeground(new java.awt.Color(0, 204, 204));
jLabel1.setText("CONTADOR DE VOCALES");
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jLabel2.setText("Ingrese texto");
txtCuenta.setForeground(new java.awt.Color(102, 102, 102));
btnAceptar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
btnAceptar.setText("Aceptar");
btnAceptar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnAceptarActionPerformed(evt);
}
});
btnNuevo.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
btnNuevo.setText("Nuevo");
btnNuevo.setActionCommand("");
btnNuevo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnNuevoActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnAceptar)
.addGap(30, 30, 30)
.addComponent(btnNuevo)
.addGap(59, 59, 59))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(72, 72, 72)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 245, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(22, 22, 22)
.addComponent(jLabel2)
.addGap(18, 18, 18)
.addComponent(txtCuenta, javax.swing.GroupLayout.PREFERRED_SIZE, 254, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(94, 94, 94)
.addComponent(lblRespuesta, javax.swing.GroupLayout.PREFERRED_SIZE, 234, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(28, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(41, 41, 41)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(txtCuenta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(28, 28, 28)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnAceptar)
.addComponent(btnNuevo))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 68, Short.MAX_VALUE)
.addComponent(lblRespuesta, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(45, 45, 45))
);
pack();
}// </editor-fold>
private void btnNuevoActionPerformed(java.awt.event.ActionEvent evt) {
limpiar(); // TODO add your handling code here:
}
private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {
aceptar(); // TODO add your handling code here:
}
private void txtCuentaActionPerformed(java.awt.event.ActionEvent evt) {
}
public static void main(String args[]) {
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(CONTADORDEVOCALES.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(CONTADORDEVOCALES.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(CONTADORDEVOCALES.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(CONTADORDEVOCALES.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new CONTADORDEVOCALES().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnAceptar;
private javax.swing.JButton btnNuevo;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel lblRespuesta;
private javax.swing.JTextField txtCuenta;
// End of variables declaration
}