62,615
社区成员
发帖
与我相关
我的任务
分享
import java.awt.*;
import java.awt.event.*;
import java.util.*;
class WindowTextArea extends Frame implements TextListener,ActionListener
{
TextArea text1,text2;
Button buttonClear;
WindowTextArea()
{
setLayout(new FlowLayout());
text1 = new TextArea(6,15);
text2 = new TextArea(6,15);
text2.setEditable(false);
buttonClear = new Button("确定");
add(text1);
add(text2);
add(buttonClear);
text1.addTextListener(this);
buttonClear.addActionListener(this);
setBounds(100,100,350,160);
setVisible(true);
validate();
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
public void textValueChanged(TextEvent e)
{
String s = text1.getText();
String[] a = s.split("\\s+");
Arrays.sort(a);
text2.setText("");
for(int i = 0; i < a.length; i++)
{
text2.append(a[i]+"\n");
}
}
public void actionPerformed(ActionEvent e)
{
text1.setText("");
}
}
public class TextAreaExa {
public static void main(String[] args) {
// TODO Auto-generated method stub
WindowTextArea win = new WindowTextArea();
}
}