问题描述
- 关于java swing的鼠标事件
-
package te;import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseListener;import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JList;import com.sun.glass.events.MouseEvent;
public class MainFrame extends JFrame {
private JPanel contentPane; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { MainFrame frame = new MainFrame(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public MainFrame() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 450, 300); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(new BorderLayout(0, 0)); setContentPane(contentPane); JList list = new JList(); contentPane.add(list, BorderLayout.CENTER); list.addMouseListener(new MouseAdapter(){ public void mouseClicked(MouseEvent e){ if(e.getClickCount==2) {} } }); }
}
比如如上建立JList,添加鼠标监听后,无法使用getclickcount()方法。而把JList单独拿出去新建个类就可以重写了。是不是因为跟MainFrame在一起所以没法重写mouseClicked方法?有没有办法在mainframe里用的?
解决方案
http://blog.csdn.net/ymc0329/article/details/6684557
时间: 2024-10-25 23:36:54