<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">import java.awt.event.*;
import java.awt.*;
import java.text.*;

public class Procura extends MinhaApplet
{
	public static void main(String argv[]) {
		(new FrameProcura(null)).show();
	}
	
	public Frame criaFrame (MinhaApplet applet) {
		return new FrameProcura(applet);
	}
}

class FrameProcura extends Frame {
	static final int LINHAS = 15;
	static final int COLUNAS = 50;
	BreakIterator enum;
	TextArea text;

	public FrameProcura(final MinhaApplet applet)
	{
		setSize(550, 500);
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				dispose();
				if (applet != null) applet.fecha();
				else System.exit(0);
			}	
		});
      
		Panel painel = new Panel();
		painel.add(new Label("Dê um clique duplo na palavra que quer procurar, e depois aperte"));
        
		Button botão = new Button("Próxima");
		botão.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) { Próximo(); }
		});
		painel.add(botão);
      
		botão = new Button("Anterior");
		botão.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) { Anterior(); }
		});
		painel.add(botão);
		add(painel, "North");
  
		text = new TextArea(textoInicial(), LINHAS, COLUNAS);
		text.addKeyListener(new KeyAdapter() {
			public void keyPressed(KeyEvent e) {
				if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
					e.consume();
					Próximo();
				} else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
					e.consume();
					Anterior();
				}
			}	
		});
		text.setEditable(false);
		text.setFont(new Font("Helvetica", Font.BOLD, 14));
		add(text, "Center");
		
		enum = BreakIterator.getWordInstance();
		enum.setText(text.getText());
	}

	public String textoInicial()
	{
		return
			"(\"This is a complete sentence.\") This is (\"not.\") also. \n"
			+"An abbreviation in the middle, etc. and one at the end, etc. "+
				"This\n"
			+"is a simple sample 012.566,5 sentence. It doesn't\n"
			+"have to make any sense, as you can see. Nel mezzo del \nc"
			+"ammin di nostra vita, mi ritrovai in una selva oscura. Che\n"
			+"la dritta via aveo smarrita. Not on my time (el timo.)! And\n"
			+"tabulated columns: \tCol1\tCol2\t3,456%.\t\n"
			+"Is this a question???  I wonder... Hmm. Harris thumbed\n"
			+"down several, including \"Away We Go\" (which became the \n"
			+"huge success Oklahoma!). One species, B. anthracis, is \n"
			+"highly virulent. Wolf said about Sounder: \"Beautifully \n"
			+"thought-out and directed.\" Have you ever said, \"This is "+
				"where I\n"
			+"shall live\"? He said 1000,233,456.000 and answered, \"You "+
				"may not!\" \n"
			+"Another popular saying is: \"How do you do?\". What is the \n"
			+"proper use of the abbreviation pp.? Yes, I am 12\' 3\" tall!!";
	}

	public void Próximo()
	{
		int oldStart = text.getSelectionStart();
		int oldEnd = text.getSelectionEnd();
		String palavra = text.getText().substring(oldStart, oldEnd);
		if (oldEnd &lt; 1) {
			text.select(0, enum.following(0));
		}
		else {
			int i = enum.following(oldEnd-1), f;
			for (f = enum.next(); f != BreakIterator.DONE; i = f, f = enum.next())
				if (palavra.equals(text.getText().substring(i, f))) {
					text.select(i, f);
					break;
				}	
		}
	}

	public void Anterior()
	{
		int oldStart = text.getSelectionStart();
		int oldEnd = text.getSelectionEnd();
		String palavra = text.getText().substring(oldStart, oldEnd);
		if (oldStart &lt; 1) {
			text.select(0, 0);
		}
		else {
			int f = enum.following(oldStart-1), i;
			for (i = enum.previous(); i != BreakIterator.DONE; f = i, i = enum.previous())
				if (palavra.equals(text.getText().substring(i, f))) {
					text.select(i, f);
					break;
				}	
		}
	}
}
</pre></body></html>