java MouseListener接口问题
publicclassPlayimplementsMouseListener{JFramef;publicPlay(){f=newJFrame();f.setSize(3...
public class Play implements MouseListener{
JFrame f;
public Play(){
f = new JFrame();
f.setSize(300,150);
f.show();
f.addMouseListener(this);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void mousePressed(MouseEvent e){System.out.print("压下");}
public void mouseReleased(MouseEvent e){System.out.print("松开");}
public void mouseEntered(MouseEvent e){System.out.print("进入");}
public void mouseExited(MouseEvent e){System.out.print("离开");}
public void mouseClicked(MouseEvent e){System.out.print("点击");}
}
class main{
public static void main(String[] args){
Play play = new Play();
System.out.print("good");
}
}
请问这MouseListener的这5个抽象方法都是一样的参数 那为什么压下鼠标这个事件就一定会执行mousePressed方法,
松开鼠标这个事件就一定会执行mouseReleased方法 也就是说 是什么让时间和方法对号入座了的啊? 展开
JFrame f;
public Play(){
f = new JFrame();
f.setSize(300,150);
f.show();
f.addMouseListener(this);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void mousePressed(MouseEvent e){System.out.print("压下");}
public void mouseReleased(MouseEvent e){System.out.print("松开");}
public void mouseEntered(MouseEvent e){System.out.print("进入");}
public void mouseExited(MouseEvent e){System.out.print("离开");}
public void mouseClicked(MouseEvent e){System.out.print("点击");}
}
class main{
public static void main(String[] args){
Play play = new Play();
System.out.print("good");
}
}
请问这MouseListener的这5个抽象方法都是一样的参数 那为什么压下鼠标这个事件就一定会执行mousePressed方法,
松开鼠标这个事件就一定会执行mouseReleased方法 也就是说 是什么让时间和方法对号入座了的啊? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询