Topic: 编写才能不必再写所不关心的事件 |
Print this page |
1.编写才能不必再写所不关心的事件 | Copy to clipboard |
Posted by: LLL_QQQ Posted on: 2004-09-14 17:29 非常感谢^_^! <1>是不是事件适配器只能继承,而不能通过接口来实现呢? <2>怎样编写才能不必再写所不关心的事件:如本例<见下面>的 public void mousePressed(MouseEvent e) {} public void mouseReleased(MouseEvent e){} public void mouseClicked(MouseEvent e){}(假如我不关心这个事件); 附: import java.awt.*; import java.awt.event.*; public class SSS extends MouseMotionAdapter implements MouseListener { private Frame f; private TextField tf; public static void main(String args[]){ SSS two=new SSS(); two.go(); } public void go(){ f=new Frame("Two listener example"); f.add(new Label("Click and drag the mouse"),"North"); tf=new TextField(30); f.add(tf,"South"); //注册监听程序 f.addMouseMotionListener(this); f.addMouseListener(this); f.setSize(300,300); f.setVisible(true); } //实现MouseMotionListener接口中的方法 public void mouseDragged(MouseEvent e){ String s="鼠标拖动="+e.getX()+"Y="+e.getY(); tf.setText; } public void mouseEntered(MouseEvent e){ String s="鼠标进入"; tf.setText; } public void mouseExited(MouseEvent e){ String s="鼠标离开"; tf.setText; } public void mousePressed(MouseEvent e) {} public void mouseReleased(MouseEvent e){} public void mouseClicked(MouseEvent e){} } |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |