今天自己写个小程序碰到了这个问题,在网上搜了一下人家的思路,整理了一下代码可以运行,感觉不错!
直接在JBuilder中新建一个应用程序,至于具体步骤就不描述了,此代码没有main函数无法直接运行。下面我贴出在Frame1中的代码:
|
import java.awt.*; import java.awt.event.*; 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(); } }
//Component initialization 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); } |