Heres my program:
// SelectCopyPaste.java by Firefox 6 June 2003
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class SelectCopyPaste extends Frame
{
Button select = new Button ("Select all");
Button copy = new Button ("Copy");
Button paste = new Button ("Paste");
Button quit = new Button ("Exit");
TextArea t1 = new TextArea (20, 20);
String s;
public SelectCopyPaste ()
{
setLayout (new BorderLayout ());
Panel pp = new Panel ();
pp.setLayout (new FlowLayout ());
select.addActionListener (new Selecter ());
copy.addActionListener (new Copier ());
paste.addActionListener (new Paster ());
quit.addActionListener (new Quitter ());
pp.add (select);
pp.add (copy);
pp.add (paste);
pp.add (quit);
add (pp, BorderLayout.NORTH);
add (t1, BorderLayout.CENTER);
}
public static void main (String [] args)
{
Frame f = new SelectCopyPaste ();
f.setSize (400, 400);
f.setVisible (true);
}
class Quitter implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
System.exit (0);
}
}
class Selecter implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
t1.selectAll ();
t1.requestFocus ();
}
}
class Copier implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
s = t1.getSelectedText ();
t1.requestFocus ();
}
}
class Paster implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
t1.insert (s, t1.getCaretPosition ());
t1.requestFocus ();
}
}
}