> But can I not use ts.getSelectedText() to set a string to have
the value of the text in the textarea that was selected by the
user when it is detected that the button was clicked on?
OK. It does work as follows:
[code]
import java.awt.*;
import java.awt.event.*;
public class Selected implements ActionListener{
TextArea ta;
TextField tf;
public Selected(){
Frame frame = new Frame();
//make the content string just ONE STRING before compile
//comp.lang.java format fragments it! No good!
ta = new TextArea("I can add an event handler for the button and
that works fine. I do not expect to have the TextArea trigger an
event. But can I not use ts.getSelectedText() to set a string to have
the value of the text in the textarea that was selected by the user
when it is detected that the button was clicked on?",
20, 60, TextArea.SCROLLBARS_VERTICAL_ONLY);
Button bt = new Button("COPY");
tf = new TextField(60);
frame.setLayout(new BorderLayout());
frame.add(tf, BorderLayout.NORTH);
frame.add(ta, BorderLayout.CENTER);
frame.add(bt, BorderLayout.SOUTH);
bt.addActionListener(this);
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);
}
});
frame.pack();
frame.show();
}
public void actionPerformed(ActionEvent e){
tf.setText(ta.getSelectedText());
}
public static void main(String[] args){
new Selected();
}
}
/code]