java问题The type MouseHander must implement the inherited abstract method MouseListener.mouseClicked

importjava.awt.*;importjavax.swing.*;importjava.awt.Event.*;importstaticjavax.swing.J... import java.awt.*;
import javax.swing.*;
import java.awt.Event.*;
import static javax.swing.JFrame.*;
public class shiyansan extends JFrame{
JTextField text1,text2,text3;
public shiyansan(){
setBounds(500,220,320,180);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new FlowLayout());
text1 = new JTextField ("",20);
text1.setHorizontalAlignment(JTextField.LEFT);
text2 = new JTextField ("",20);
text3 = new JTextField ("",20);
text1.addMouseListener(new MouseHander(text1));
text3.addMouseMotionListener(new MouseMotionHander());
text2.addMouseMotionListener(new MouseMotionHander());
add(text1);
add(text2);
add(text3);
}

public static void main(String args[]){
shiyansan win = new shiyansan();
win.setTitle("Sum of two numbers");
}
}

public class MouseHander extends shiyansan implements MouseListener{
JTextField current;
public MouseHander(JTextField c){
current = c;
}
public void mousePressed(MouseEvent event){
if(current==text3) {
double firstNumber = Double.parseDouble(text1.getText());
double secondNumber = Double.parseDouble(text2.getText());
double Result = firstNumber + secondNumber;
text3.setText(""+Result);
}
else
current.setText("");
}
}

public class MouseMotionHander extends shiyansan implements MouseMotionListener{
public void mouseMoved(MouseEvent event){
double number=Double.parseDouble(text1.getText());
if(number<100||number>200){
int type = JOptionPane.ERROR_MESSAGE;
JOptionPane.showMessageDialog(null,new String("输入数字必须在100~200之间"),"提示", 2);
}
}
}

有错误提示:1.The type MouseHander must implement the inherited abstract method MouseListener.mouseClicked(MouseEvent)
2.The type MouseMotionHander must implement the inherited abstract method MouseMotionListener.mouseDragged(MouseEvent)
功能:前两个文本框输入整型数据。第三个文本框存放前两个文本框数据之和。
要求如下:
第一个文本框的数据是[100,200],如果超出该范围弹出对话框提示用户。弹出提示对话框的时刻是光标离开第一个文本框时。
展开
 我来答
百度网友8a0ff05
2012-05-28 · TA获得超过130个赞
知道小有建树答主
回答量:328
采纳率:0%
帮助的人:170万
展开全部
你要用鼠标响应事件就必须实现mouseListener接口,第二个问题同理。public class shiyansan extends JFrame implements mouseListener,MouseMotionListener。再中实现这两个接口的函数就行了。
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式