shuangjishijian.java
来自「java+sql 图书管理系统」· Java 代码 · 共 97 行
JAVA
97 行
package MyLibraryok.MySwing;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Date;
//import com.borland.jbcl.layout.*;
public class shuangjishijian 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;
//XYLayout xYLayout2 = new XYLayout();
//Construct the frame
public shuangjishijian() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel)this.getContentPane();
contentPane.setLayout(borderLayout1);
this.setLocale(java.util.Locale.getDefault());
this.setBounds(100,100,500,500);
this.setVisible(true);
this.setSize(new Dimension(532, 468));
this.setTitle("Frame Title");
jPanel1.setLayout(null);
jList1.addMouseListener(new Frame1_jList1_mouseAdapter(this));
contentPane.add(jPanel1, BorderLayout.CENTER);
jPanel1.add(jScrollPane1);
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 {
shuangjishijian adaptee;
Frame1_jList1_mouseAdapter(shuangjishijian adaptee) {
this.adaptee = adaptee;
}
public void mouseReleased(MouseEvent e) {
adaptee.jList1_mouseReleased(e);
}
}
public static void main(String[] args) {
shuangjishijian d = new shuangjishijian();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?