Chinaunix首页 | 论坛 | 博客
  • 博客访问: 199305
  • 博文数量: 163
  • 博客积分: 4010
  • 博客等级: 上校
  • 技术积分: 1720
  • 用 户 组: 普通用户
  • 注册时间: 2009-06-08 11:41
文章分类

全部博文(163)

文章存档

2011年(1)

2009年(162)

我的朋友

分类: Java

2009-07-07 17:53:52

 直接在JBuilder中新建一个应用程序,至于具体步骤就不描述了,此代码没有main函数无法直接运行。下面我贴出在Frame1中的代码:

 


    import Java.awt.*;
  import java.awt.event.*;
  import javax.Swing.*;
  import comborland.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();
  }
  }

   //component initialzation

  
  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);
  }
  }
阅读(353) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~