java求解:帮忙怎么解决下面的问题,具体些,谢谢!
importjava.awt.BorderLayout;importjava.awt.GridLayout;importjava.awt.event.ActionEven...
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JLabel;
class Callator extends JFrame implements ActionListener {
JLabel jl1, jl2, jl3;
JTextField jt1, jt2, jt3;
JButton jb1, jb2, jb3, jb4;
Callator() {
jl1 = new JLabel("数值一:");
jl2 = new JLabel("数值二:");
jl3 = new JLabel("数值三:");
jt1 = new JTextField(5);
jt2 = new JTextField(5);
jt3 = new JTextField(5);
jt3.setEditable(false);
JPanel jp1 = new JPanel(new GridLayout(3, 2));
jp1.add(jl1);
jp1.add(jt1);
jp1.add(jl2);
jp1.add(jt2);
jp1.add(jl3);
jp1.add(jt3);
jb1 = new JButton("+");
jb2 = new JButton("-");
jb3 = new JButton("*");
jb4 = new JButton("/");
JPanel jp2 = new JPanel();
jp2.add(jb1);
jp2.add(jb2);
jp2.add(jb3);
jp2.add(jb4);
add(jp1);
add(jp2, BorderLayout.SOUTH);
jb1.addActionListener(this);
jb2.addActionListener(this);
jb3.addActionListener(this);
jb4.addActionListener(this);
}
public void actionPerforemed(ActionEvent e) {
String s1 = jt1.getText();
String s2 = jt2.getText();
Double d1 = new Double(s1);
double num1 = d1.doubleValue();
double num2 = new Double(s2);
double total = 0;
if (e.getSource() == jb1)
total = num1 + num2;
else if (e.getSource() == jb2)
total = num1 - num2;
else if (e.getSource() == jb3)
total = num1 * num2;
else if (e.getSource() == jb4)
total = num1 / num2;
String s3 = (new Double(total)).toString();
jt3.setText(s3);
}
}
public class Test11 {
public static void main(String[] args) {
Callator f = new Callator();
f.setSize(200, 150);
f.setLocation(333, 333);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
编译后出现这句话:
The type Callator must implement the inherited abstract method ActionListener.actionPerformed(ActionEvent)
求解决方法。 展开
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JLabel;
class Callator extends JFrame implements ActionListener {
JLabel jl1, jl2, jl3;
JTextField jt1, jt2, jt3;
JButton jb1, jb2, jb3, jb4;
Callator() {
jl1 = new JLabel("数值一:");
jl2 = new JLabel("数值二:");
jl3 = new JLabel("数值三:");
jt1 = new JTextField(5);
jt2 = new JTextField(5);
jt3 = new JTextField(5);
jt3.setEditable(false);
JPanel jp1 = new JPanel(new GridLayout(3, 2));
jp1.add(jl1);
jp1.add(jt1);
jp1.add(jl2);
jp1.add(jt2);
jp1.add(jl3);
jp1.add(jt3);
jb1 = new JButton("+");
jb2 = new JButton("-");
jb3 = new JButton("*");
jb4 = new JButton("/");
JPanel jp2 = new JPanel();
jp2.add(jb1);
jp2.add(jb2);
jp2.add(jb3);
jp2.add(jb4);
add(jp1);
add(jp2, BorderLayout.SOUTH);
jb1.addActionListener(this);
jb2.addActionListener(this);
jb3.addActionListener(this);
jb4.addActionListener(this);
}
public void actionPerforemed(ActionEvent e) {
String s1 = jt1.getText();
String s2 = jt2.getText();
Double d1 = new Double(s1);
double num1 = d1.doubleValue();
double num2 = new Double(s2);
double total = 0;
if (e.getSource() == jb1)
total = num1 + num2;
else if (e.getSource() == jb2)
total = num1 - num2;
else if (e.getSource() == jb3)
total = num1 * num2;
else if (e.getSource() == jb4)
total = num1 / num2;
String s3 = (new Double(total)).toString();
jt3.setText(s3);
}
}
public class Test11 {
public static void main(String[] args) {
Callator f = new Callator();
f.setSize(200, 150);
f.setLocation(333, 333);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
编译后出现这句话:
The type Callator must implement the inherited abstract method ActionListener.actionPerformed(ActionEvent)
求解决方法。 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询