- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- public class Main extends JFrame {
- .FlowLayout v = new FlowLayout();
- .JButton boton1 = new JButton(" Revertir ");
- .TextArea text = new TextArea("", 3, 30, 3);//row,col,nullScroll
- .public Main() {
- ...text.setText("Hola mundo");
- ...add(text);
- ...add(boton1);
- ...getContentPane().setLayout(v);
- ...setDefaultCloseOperation(EXIT_ON_CLOSE);
- ...setSize(300,150);
- ...setVisible(true);
- //Event al pulsar boton
- ...boton1.addActionListener (new ActionListener(){
- ....public void actionPerformed(ActionEvent e){
- .....StringBuffer str1 = new StringBuffer(text.getText());
- ........text.setText(str1.reverse().toString());
- ......}
- ....});
- ..}
- ..public static void main(String[] args) { new Main(); }
- }
Una forma sencilla y rápida de aprender JAVA, observando y deduciendo cómo se comporta el lenguaje a través de ejemplos prácticos.
Archivo del blog
martes, 16 de marzo de 2010
Uso de StringBuffer. reverse (invertir strings).
Codigo:
Suscribirse a:
Entradas (Atom)
Con la tecnología de Blogger.