請幫助我解決問題。當lblCur輸入lblBnt時,Mousemouse事件無法正常工作。它看起來像滯後的,差的FPS或類似的東西。在jLabel中使用mousemove事件創建自定義光標
如果我刪除lblBtn.addMouseListener(...),lblBg.addMouseMotionListener(...)工作正常!但我不能讓事件,當我在lblBnt點擊...
代碼:http://pastebin.com/ZBJySGEq
public myjFrame()
{
setCursor(Toolkit.getDefaultToolkit().createCustomCursor(new ImageIcon(UrlImg("cur_empty.png")).getImage(),new Point(0,0),"cursor_default"));
this.setLayout(new BorderLayout());
lblBg= new JLabel();
lblBg.setIcon(new ImageIcon(UrlImg("main_menu_bg.png")));
lblBg.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
public void mouseDragged(java.awt.event.MouseEvent evt) {
cMouseDragged(evt);
}
public void mouseMoved(java.awt.event.MouseEvent evt) {
cMouseMoved(evt);
}
});
this.add(lblBg);
lblBg.setLayout(null);`
lblBtn= new JLabel();
lblBtn.setIcon(new ImageIcon(UrlImg("choi.png")));
lblBtn.setBounds(120, 310, 345, 132);
lblBtn.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
lblChoiMouseClicked(evt);
}
public void mouseEntered(java.awt.event.MouseEvent evt) {
lblChoiMouseEntered(evt);
}
public void mouseExited(java.awt.event.MouseEvent evt) {
lblChoiMouseExited(evt);
}
});
lblBg.add(lblBtn);
lblCur= new JLabel();
lblCur.setIcon(new ImageIcon(UrlImg("cur_def.png")));
lblCur.setBounds(200, 200, 155, 155);
lblCur.setText("");
lblBg.add(lblCur);
}
private void cMouseMoved(java.awt.event.MouseEvent evt) {
lblBg.add(lblBtn);
lblCur.setLocation(evt.getX()-40,evt.getY()-40);
}
private void cMouseDragged(java.awt.event.MouseEvent evt) {
lblCur.setLocation(evt.getX()-40,evt.getY()-40);
}
private void lblChoiMouseEntered(java.awt.event.MouseEvent evt) {
lblBtn.setIcon(new ImageIcon(UrlImg("choi_hover.png")));
}
private void lblChoiMouseExited(java.awt.event.MouseEvent evt) {
lblBtn.setIcon(new ImageIcon(UrlImg("choi.png")));
}
private void lblChoiMouseClicked(java.awt.event.MouseEvent evt) {
this.dispose();
}
public static void main(String[] args) {
myjFrame main= new myjFrame();
main.setBounds(100, 100, 769,892);
main.setVisible(true);
}
}
項目:https://drive.google.com/open?id=0Bw0by9qPYJ8TTWoydGtGbHZMbU0
提前感謝!
你在哪裏渲染?讀完代碼後,我找不到重繪() – user7185318
在論壇中發佈適當的[mcve]問題,而不是在外部網站上。 – camickr
請在此處發佈可疑代碼,而不是其他鏈接 – HenryM