java小程序有错误,高手帮忙
importjava.awt.*;importjava.awt.event.*;classwinextendsFrameimplementsTextListener,Ac...
import java.awt.*;
import java.awt.event.*;
class win extends Frame implements TextListener,ActionListener
{TextArea text1,text2;
Button button;
win(s)
{super(s);
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(100,100,300,300);
setVisable(ture);
validate();
}
public void textValueChanged(TextEvent e)
{String a[];int b[];int sum=0;float avr;
StringTokenizer x=new StringTokenizer(s," '");
int n=x.countTokens();
for(int i=0;i<=n;i++)
{a[i]=x.nextToken();
b[i]=Integer.parseInt(a[i]);
sum=sum+b[i];
}
avr=sum/n;
text2.setText("sum:"+sum+"avr:"+avr);
}
public void actionPerformed(ActionEvent e)
{text1.setText(null);
}
}
public class AA
{public static void main (String[] args) {
a A=new a("习题7.4");
}
} 展开
import java.awt.event.*;
class win extends Frame implements TextListener,ActionListener
{TextArea text1,text2;
Button button;
win(s)
{super(s);
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(100,100,300,300);
setVisable(ture);
validate();
}
public void textValueChanged(TextEvent e)
{String a[];int b[];int sum=0;float avr;
StringTokenizer x=new StringTokenizer(s," '");
int n=x.countTokens();
for(int i=0;i<=n;i++)
{a[i]=x.nextToken();
b[i]=Integer.parseInt(a[i]);
sum=sum+b[i];
}
avr=sum/n;
text2.setText("sum:"+sum+"avr:"+avr);
}
public void actionPerformed(ActionEvent e)
{text1.setText(null);
}
}
public class AA
{public static void main (String[] args) {
a A=new a("习题7.4");
}
} 展开
4个回答
展开全部
import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.TextEvent;
import java.awt.event.TextListener;
import java.util.StringTokenizer;
class win extends Frame implements TextListener, ActionListener {
TextArea text1, text2;
Button button;
private String s;
win(String s) {
super(s);
this.s = s;
text1 = new TextArea();
text1.addTextListener(this);
text2 = new TextArea();
text2.setEditable(false);
button = new Button("清空");
button.addActionListener(this);
setLayout(new FlowLayout());
add(text1);
add(text2);
add(button);
setBounds(100, 100, 300, 300);
setVisible(true);
validate();
}
public void textValueChanged(TextEvent e) {
int sum = 0;
float avr;
StringTokenizer x = new StringTokenizer(s, " '");
int n = x.countTokens();
String a[] = new String[n];
int b[] = new int[n];
for(int i=0; x.hasMoreTokens(); i++){
a[i] = (String)x.nextElement();
b[i] = Integer.parseInt(a[i]);
sum = sum + b[i];
}
avr = sum / n;
text2.setText("sum:" + sum + "avr:" + avr);
}
public void actionPerformed(ActionEvent e) {
text1.setText(null);
}
}
public class AA {
public static void main(String[] args) {
// A a=new A("习题7.4");
win a = new win("123");
}
}
帮你改了改 我只让它能运行起来 具体的内容还要你自己根据需要进行修改
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.TextEvent;
import java.awt.event.TextListener;
import java.util.StringTokenizer;
class win extends Frame implements TextListener, ActionListener {
TextArea text1, text2;
Button button;
private String s;
win(String s) {
super(s);
this.s = s;
text1 = new TextArea();
text1.addTextListener(this);
text2 = new TextArea();
text2.setEditable(false);
button = new Button("清空");
button.addActionListener(this);
setLayout(new FlowLayout());
add(text1);
add(text2);
add(button);
setBounds(100, 100, 300, 300);
setVisible(true);
validate();
}
public void textValueChanged(TextEvent e) {
int sum = 0;
float avr;
StringTokenizer x = new StringTokenizer(s, " '");
int n = x.countTokens();
String a[] = new String[n];
int b[] = new int[n];
for(int i=0; x.hasMoreTokens(); i++){
a[i] = (String)x.nextElement();
b[i] = Integer.parseInt(a[i]);
sum = sum + b[i];
}
avr = sum / n;
text2.setText("sum:" + sum + "avr:" + avr);
}
public void actionPerformed(ActionEvent e) {
text1.setText(null);
}
}
public class AA {
public static void main(String[] args) {
// A a=new A("习题7.4");
win a = new win("123");
}
}
帮你改了改 我只让它能运行起来 具体的内容还要你自己根据需要进行修改
展开全部
//估计这应该是楼主想要的。以 ' 作为分隔,把 '两边的数相加。
import java.awt.*;
import java.awt.event.*;
import java.util.StringTokenizer;
class win extends Frame implements TextListener, ActionListener {
TextArea text1, text2;
Button button;
win(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[1000];
int b[] = new int[1000];
int sum = 0;
float avr = 0;
String s = text1.getText();
StringTokenizer x = new StringTokenizer(s, "'");
System.out.println("x:" + x);
int n = x.countTokens();
System.out.println("n:" + n);
for (int i = 0; i < n; i++) {
a[i] = x.nextToken();
b[i] = Integer.parseInt(a[i]);
sum = sum + b[i];
}
avr = sum / n;
text2.setText("sum:" + sum + "avr:" + avr);
}
public void actionPerformed(ActionEvent e) {
text1.setText(null);
}
public static void main(String[] args) {
win A = new win("习题7.4");
}
}
import java.awt.*;
import java.awt.event.*;
import java.util.StringTokenizer;
class win extends Frame implements TextListener, ActionListener {
TextArea text1, text2;
Button button;
win(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[1000];
int b[] = new int[1000];
int sum = 0;
float avr = 0;
String s = text1.getText();
StringTokenizer x = new StringTokenizer(s, "'");
System.out.println("x:" + x);
int n = x.countTokens();
System.out.println("n:" + n);
for (int i = 0; i < n; i++) {
a[i] = x.nextToken();
b[i] = Integer.parseInt(a[i]);
sum = sum + b[i];
}
avr = sum / n;
text2.setText("sum:" + sum + "avr:" + avr);
}
public void actionPerformed(ActionEvent e) {
text1.setText(null);
}
public static void main(String[] args) {
win A = new win("习题7.4");
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
super(s);换成super();
public class AA 换成class AA
试试,
还有就是a A=new a("习题7.4");看不到
public class AA 换成class AA
试试,
还有就是a A=new a("习题7.4");看不到
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
时间处理时
text1.setText("");
text1.setText("");
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询