各位大哥帮帮忙,才学不久,不知道哪错了
import javax.swing.*;
import java.awt. *;
import java.awt.event. *;
import java.applet.Applet;
public class Addition extends Applet implements ActionListener{
Label label = new Label( "+ ");
Label labe2 = new Label( "= ");
TextField fieldl=new TextField(6);
TextField field2=new TextField(6);
TextField field3=new TextField(6);
JButton b1=new JButton( "相加 ");
public void init() {
add(field1);
add(label1);
add(field2);
add(label2);
add(field3);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
int x=Integer.parseInt(field1.getText())+Integer.parseInt(field2.getText());
field3.setText(Integer.toString(x));
}
}
------解决方案--------------------package com.applet;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class Addition extends Applet implements ActionListener {
Label label = new Label( "+ ");
Label labe2 = new Label( "= ");
TextField fieldl = new TextField(6);
TextField field2 = new TextField(6);
TextField field3 = new TextField(6);
JButton b1 = new JButton( "相加 ");
public void init() {
add(fieldl);
add(label);
add(field2);
add(labe2);
add(field3);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
int x = Integer.parseInt(fieldl.getText())
+ Integer.parseInt(field2.getText());
field3.setText(Integer.toString(x));
}
}