当前位置: 代码迷 >> Java相关 >> java鼠标监听角色移动为什么老出现瞬移,
  详细解决方案

java鼠标监听角色移动为什么老出现瞬移,

热度:307   发布时间:2013-09-12 17:12:41.0
java鼠标监听角色移动为什么老出现瞬移,
用鼠标点击获取到x轴坐标然后点击移动,老是出现瞬移的情况怎么解决,
以下是代码:
public class dddd extends Thread implements MouseMotionListener,MouseListener{
private int m=0;
private JPanel backgd;
private JLabel label;
JFrame jf=new JFrame();
    public dddd() {

           itnt();

    }

    private void itnt() {
// TODO Auto-generated method stub
        jf.setTitle("星际争霸");
double width = Toolkit.getDefaultToolkit().getScreenSize().width;
double height = Toolkit.getDefaultToolkit().getScreenSize().height;

jf.setSize((int)width,(int)height);
jf.setLocation(0,0);
jf.setResizable(false);

jf.addMouseListener(this);  
        jf.addMouseMotionListener(this);  
        jf.addWindowListener(new WindowAdapter() {  
            @Override  
            public void windowClosing(WindowEvent e) {  
                // TODO Auto-generated method stub  
                System.exit(0);  
            }  
        });
        
backgd = new JPanel(){
public void paintComponent (Graphics g){
ImageIcon icon =new ImageIcon(
dddd.class.getResource("/img/9-1.jpg") );
g.drawImage(icon.getImage(), 0, 0, this.getSize().width, this.getSize().height,
this);
}
};
jf.getContentPane().add(backgd);
backgd.setLayout(null);
label = new JLabel("");
label.setIcon(new ImageIcon(Ling.class.getResource("/img/0_firebat_red_atk4.gif")));
label.setBounds(0, 154, 370, 229);
backgd.add(label);
jf.setVisible(true);


}



@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
if (e.getClickCount()==1) {  
        System.out.println("单击!");
        m=e.getX();
        for(int i=0;i<m;i++){//
// label.setIcon(new ImageIcon(Ling.class.getResource("")));   
try {
Thread.sleep(11);   
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
label.setBounds(i,333, 370, 229);   
}
        }
        
      
}

@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub

}

@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub

}

@Override
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub

}

@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub

}

@Override
public void mouseDragged(MouseEvent arg0) {
// TODO Auto-generated method stub

}

@Override
public void mouseMoved(MouseEvent arg0) {
// TODO Auto-generated method stub

}
}
搜索更多相关的解决方案: 星际争霸  private  public  double  method  

----------------解决方案--------------------------------------------------------
  相关解决方案