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);
buttonClear=new Button("clear");
add(text1);
add(text2);
add(buttonClear);
text2.setEditable(false);
text1.addTextListener(this);
buttonClear.addActionListener(this);
setBounds(100,100,350,160);
setVisible(true);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
validate();
}
public void textValueChagned(TextEvent e)
{
String s=text1.getText();
StringTokenizer fenxi=new StringTokenizer(s," ,'\n'");
int n=fenxi.countTokens();
String a[]=new String[n];
for(int i=0;i<=n-1;i++)
{
String temp=fenxi.nextToken();
a[i]=temp;
}
Arrays.sort(a);
text2.setText(null);
for(int i=0;i<n;i++)
{
text2.append(a[i]+"\n");
}
}
public void actionPerformed(ActionEvent e)
{
text1.setText(null);
}
}
public class pro146
{
public static void main(String args[])
{
WindowTextArea win=new WindowTextArea();
}
}
错误如下:
WindowTextArea 不是抽象的,并且未覆盖 java.awt.event.TextListener 中的抽象方法 textValueChanged(java.awt.event.TextEvent)
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);
buttonClear=new Button("clear");
add(text1);
add(text2);
add(buttonClear);
text2.setEditable(false);
text1.addTextListener(this);
buttonClear.addActionListener(this);
setBounds(100,100,350,160);
setVisible(true);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
validate();
}
public void textValueChagned(TextEvent e)
{
String s=text1.getText();
StringTokenizer fenxi=new StringTokenizer(s," ,'\n'");
int n=fenxi.countTokens();
String a[]=new String[n];
for(int i=0;i<=n-1;i++)
{
String temp=fenxi.nextToken();
a[i]=temp;
}
Arrays.sort(a);
text2.setText(null);
for(int i=0;i<n;i++)
{
text2.append(a[i]+"\n");
}
}
public void actionPerformed(ActionEvent e)
{
text1.setText(null);
}
}
public class pro146
{
public static void main(String args[])
{
WindowTextArea win=new WindowTextArea();
}
}
错误如下:
WindowTextArea 不是抽象的,并且未覆盖 java.awt.event.TextListener 中的抽象方法 textValueChanged(java.awt.event.TextEvent)
import java.awt.event.*;
import java.util.*;
class WindowTextArea extends Frame implements TextListener,ActionListener
{
TextArea text1,text2;
Button buttonClear;
public void textValueChanged(java.awt.event.TextEvent evt){
//这里放处理事件的代码。
}
WindowTextArea()
{
setLayout(new FlowLayout());
text1=new TextArea(6,15);
text2=new TextArea(6,15);
buttonClear=new Button("clear");
add(text1);
add(text2);
add(buttonClear);
text2.setEditable(false);
text1.addTextListener(this);
buttonClear.addActionListener(this);
setBounds(100,100,350,160);
setVisible(true);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
validate();
}
public void textValueChagned(TextEvent e)
{
String s=text1.getText();
StringTokenizer fenxi=new StringTokenizer(s," ,'\n'");
int n=fenxi.countTokens();
String a[]=new String[n];
for(int i=0;i <=n-1;i++)
{
String temp=fenxi.nextToken();
a[i]=temp;
}
Arrays.sort(a);
text2.setText(null);
for(int i=0;i <n;i++)
{
text2.append(a[i]+"\n");
}
}
public void actionPerformed(ActionEvent e)
{
text1.setText(null);
}
}
public class pro146
{
public static void main(String args[])
{
WindowTextArea win=new WindowTextArea();
}
}