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],如果超出该范围弹出对话框提示用户。弹出提示对话框的时刻是光标离开第一个文本框时。 展开
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],如果超出该范围弹出对话框提示用户。弹出提示对话框的时刻是光标离开第一个文本框时。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询