| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 441 人关注过本帖
标题:java鼠标监听角色移动为什么老出现瞬移,
取消只看楼主 加入收藏
mashunty
Rank: 1
等 级:新手上路
帖 子:4
专家分:9
注 册:2013-9-11
收藏
 问题点数:0 回复次数: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 
2013-09-12 17:12
快速回复:java鼠标监听角色移动为什么老出现瞬移,
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026101 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved