帮忙做做这个了急用啊要对的啊

来源:百度知道 编辑:UC知道 时间:2024/09/24 07:09:28
编写应用程序,有一个标题为“计算的窗口”的窗口,窗口的布局为FlowLayout布局。窗口中添加两个文本区,当我们在一个文本区中输入若干个数时,另一个文本区同时对输入的数进行求和运算并求出平均值,也就是说随着输入的变化,另一个文本区不断的更新求和及平均值。

//以":" 做为若干数的分隔,如在第一个文本区输入 123:123 这样会计算和为:246 平均值为: 123

import java.awt.*;
import java.awt.event.*;
import java.util.StringTokenizer;

class TextChange extends Frame implements TextListener, ActionListener {
TextArea text1, text2;
Button button;

TextChange(String s) {
super(s);
setLayout(new FlowLayout(FlowLayout.LEFT));
text1 = new TextArea();
text1.addTextListener(this);
text2 = new TextArea();
text2.setEditable(false);
button = new Button("清空");
button.addActionListener(this);
add(text1);
add(text2);
add(button);
setBounds(500, 200, 500, 400);
setVisible(true);
validate();
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}

public void textValueChanged(TextEvent e) {
String a[] = new String[