viernes, 20 de mayo de 2011

Ejemplo Java: actionPerformed ActionEvent ActionListener

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
/*
<APPLET
    CODE=buscar.class
    WIDTH=200
    HEIGHT=200 >
</APPLET>
*/
public class buscar extends Applet implements ActionListener
{
    TextArea textarea1;
    Button button1;
    public void init()
    {
        textarea1 = new TextArea("Ya es la hora.", 5, 20, TextArea.SCROLLBARS_BOTH);
        add(textarea1);
        button1 = new Button("Buscar \"hora\"");
        add(button1);
        button1.addActionListener(this);
    }
    public void actionPerformed (ActionEvent e){
        if(e.getSource() == button1){
            String s = textarea1.getText();
            String s2 = new String("hora");
            int location = s.indexOf(s2);
            textarea1.select(location, location + s2.length()) ;
        }
    }
}
Compartir:

0 comentarios:

Publicar un comentario