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

Ejercicios String

The document describes a Java program that uses three string commands: CAMBIAR, BORRAR, and CONTAR. The program contains a graphical user interface with text fields and buttons. The CAMBIAR button replaces a substring in one text field with a string from another field. The BORRAR button clears all the text fields. The CONTAR button counts the characters in a text field and displays the count.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Ejercicios String

The document describes a Java program that uses three string commands: CAMBIAR, BORRAR, and CONTAR. The program contains a graphical user interface with text fields and buttons. The CAMBIAR button replaces a substring in one text field with a string from another field. The BORRAR button clears all the text fields. The CONTAR button counts the characters in a text field and displays the count.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Actividad

Comandos de tipo STRING


REALIZAR UN PROGRAMA CON TRES COMANDOS DE TIPO STRING.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* NewJFrame.java
*
* Created on 10-jul-2015, 10:05:15
*/
package javaapplication11;

import javax.swing.JOptionPane;

/**
*
* @author vaio
*/
public class NewJFrame extends javax.swing.JFrame {

/** Creates new form NewJFrame */


public NewJFrame() {
initComponents();

/** This method is called from within the constructor to


* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jButton1 = new javax.swing.JButton();


jLabel1 = new javax.swing.JLabel();
JpalabraO = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
Jcambio = new javax.swing.JTextField();
Jingreso = new javax.swing.JTextField();
Jmensaje = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jButton1.setText("CAMBIO");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jLabel1.setText("INGRESE UN MENSAJE");

JpalabraO.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
JpalabraOActionPerformed(evt);
}
});

jLabel2.setText("INGRESE QUE DESEA CAMBIAR:");

Jcambio.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
JcambioActionPerformed(evt);
}
});

jLabel3.setText("INGRESE UNA PALABRA:");

jLabel4.setText("MENSAJE");

jButton2.setText("limpiar");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

jButton3.setText("UNIR");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});

UNIR

jButton4.setText("CONTAR");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);

}
});

javax.swing.GroupLayout layout = new


javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEA
DING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEA
DING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEA
DING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEA
DING, false)
.addComponent(jLabel3,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel2,
javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE))

.addComponent(jLabel4,
javax.swing.GroupLayout.PREFERRED_SIZE, 114,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(49, 49, 49))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1,
javax.swing.GroupLayout.DEFAULT_SIZE, 210, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEA
DING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAI
LING, false)
.addComponent(Jingreso,
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(JpalabraO,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE, 223, Short.MAX_VALUE)
.addComponent(Jmensaje,
javax.swing.GroupLayout.Alignment.LEADING))
.addComponent(Jcambio,
javax.swing.GroupLayout.DEFAULT_SIZE, 224, Short.MAX_VALUE)))
.addGroup(layout.createSequentialGroup()
.addGap(62, 62, 62)
.addComponent(jButton1)
.addGap(38, 38, 38)
.addComponent(jButton3)
.addGap(31, 31, 31)
.addComponent(jButton4)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 38,
Short.MAX_VALUE)
.addComponent(jButton2)
.addGap(11, 11, 11)))
.addGap(79, 79, 79))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(30, 30, 30)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAI
LING)
.addComponent(JpalabraO,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1,
javax.swing.GroupLayout.PREFERRED_SIZE, 24,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(24, 24, 24)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEA
DING)
.addComponent(jLabel2,
javax.swing.GroupLayout.PREFERRED_SIZE, 31,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Jcambio,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BAS
ELINE)
.addComponent(Jingreso,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3,
javax.swing.GroupLayout.PREFERRED_SIZE, 25,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BAS
ELINE)
.addComponent(Jmensaje,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4,
javax.swing.GroupLayout.PREFERRED_SIZE, 18,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(63, 63, 63)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BAS
ELINE)
.addComponent(jButton1)
.addComponent(jButton3)
.addComponent(jButton4)
.addComponent(jButton2))
.addContainerGap(75, Short.MAX_VALUE))
);

pack();
}// </editor-fold>

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


// TODO add your handling code here:}
String X,Y,Z;
X=JpalabraO.getText();
Y=Jcambio.getText();
Z=Jingreso.getText();
X=X.replace(Y, Z);
Jmensaje.setText(X);

CAMBIO

private void JpalabraOActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:

private void JcambioActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
}

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


// TODO add your handling code here:
String X,Y,Z;
JpalabraO.setText("");
Jcambio.setText(" ");
Jingreso.setText(" ");
Jmensaje.setText("");

BORRAR

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:

String str,str2;
str=JpalabraO.getText();
str2=Jingreso.getText();
str=str.concat(str2);
Jmensaje.setText(str);
}

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
String str;
str=JpalabraO.getText();
int a = str.length();
JOptionPane.showMessageDialog(null,"el numero de letras es:"+a);
}

CONTAR

/**
* @param args the command line arguments

*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<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(NewJFrame.class.getName()).log(java.util.log
ging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.log
ging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.log
ging.Level.SEVERE, null, ex);

} catch (javax.swing.UnsupportedLookAndFeelException ex) {


java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.log
ging.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */


java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {


new NewJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextField Jcambio;
private javax.swing.JTextField Jingreso;
private javax.swing.JTextField Jmensaje;
private javax.swing.JTextField JpalabraO;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;

private javax.swing.JLabel jLabel4;


// End of variables declaration
}

You might also like