模拟鼠标双击事件,请大家帮帮我,谢谢!
解决方案 »
- 关于JAVA SE中克隆clone方法的问题
- 新人快帮我谢谢给分解决马上结贴
- 输出1,2,2,3,4,5的所有排列组合,4不能在第三位,3和5不能相邻
- 界面连数据库问题,小弟在线等
- Class.forName("Gum")为什么不能加载GUM类
- 关于java编译:只修改class A并重新编译A,与A关联的其他class不重新编译有没有影响?
- 求查询分拆字符串的方法..
- Jframe的setlayout(null)代表什么涵义?
- applet invalid stream header
- 为何我的JTabbedPane上只能放一个控件?
- 如何将一个string类型的字符串转化成URL类型呀~~~
- 覆盖
import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.util.Date;
public class Frame1 extends JFrame {
JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout();
JPanel jPanel1 = new JPanel();
XYLayout xYLayout1 = new XYLayout();
JScrollPane jScrollPane1 = new JScrollPane();
JList jList1 = new JList();
//初始化的JList中的数据
String[] strData = {"One", "Tow", "Three"};
//保存点击按钮的时间
long clickTime = 0;
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
contentPane = (JPanel)this.getContentPane();
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(532, 468));
this.setTitle("Frame Title");
jPanel1.setLayout(xYLayout1);
jList1.addMouseListener(new Frame1_jList1_mouseAdapter(this));
contentPane.add(jPanel1, BorderLayout.CENTER);
jPanel1.add(jScrollPane1, new XYConstraints(18, 34, 209, 326));
jScrollPane1.getViewport().add(jList1, null);
jList1.setListData(strData);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
//判断是否双击,是的话写你要实现的功能
public boolean checkClickTime() {
long nowTime = (new Date()).getTime();
if ( (nowTime - clickTime) < 300) {
clickTime = nowTime;
return true;
}
clickTime = nowTime;
return false;
}
//具体实现按钮双击的功能的方法, 很简单的算法,不做解释了
void jList1_mouseReleased(MouseEvent e) {
if (checkClickTime()) {
System.out.println("Click Double");
}
}
}
class Frame1_jList1_mouseAdapter extends java.awt.event.MouseAdapter {
Frame1 adaptee;
Frame1_jList1_mouseAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void mouseReleased(MouseEvent e) {
adaptee.jList1_mouseReleased(e);
}
}
不过非常感谢laughsmile(海边的星空),你的思路应该是正确的,迟点我试试,谢谢 :)
先结贴