| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 840 人关注过本帖
标题:我想制作一个 可以来回移动的圆 会的帮下忙写下代码
只看楼主 加入收藏
xwsnhy
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2008-8-31
收藏
 问题点数:0 回复次数:0 
我想制作一个 可以来回移动的圆 会的帮下忙写下代码
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Game extends KeyAdapter  implements Runnable, MouseListener,MouseMotionListener
{   
    //定义变量(在下面)-----------------------------------------------------

    //定义变量(结束)--------------------------------------------------------    
    int mx=0;
    int my=0;
    boolean start=false;
    JFrame frame;
    Thread timerThread;

    Game()
    {  
        //构造初始(在下面)-----------------------------------------------------


        //构造初始(结束)--------------------------------------------------------    
        
        frame = new JFrame();
        frame.getContentPane().add(new Screen());
        frame.addKeyListener(this);   
        Container contentPane=frame.getContentPane();
        contentPane.addMouseListener(this);
        contentPane.addMouseMotionListener(this);

        //窗口大小  frame.setSize(宽, 高);
        frame.setSize(800+5*2, 800+22+5*2);

        frame.setVisible(true);
        frame.repaint();
    }
    public void mousePressed(MouseEvent e){}
    public void mouseReleased(MouseEvent e){}
    public void mouseEntered(MouseEvent e){}     
    public void mouseExited(MouseEvent e){}
    public void mouseDragged(MouseEvent e){}  

    //鼠标单击   
    public void mouseClicked(MouseEvent e)
    {
        //鼠标左键
        if (e.getButton()==MouseEvent.BUTTON1)
        {
            //鼠标位置
            int mx=e.getX();
            int my=e.getY();

            //鼠标左键处理(在下面)-----------------------------------------------------


            //鼠标左键处理(结束)--------------------------------------------------------                
        }
        //鼠标右键
        else if(e.getButton()==MouseEvent.BUTTON3)
        {
            //鼠标位置
            int mx=e.getX();
            int my=e.getY();

            //鼠标右键处理(在下面)-----------------------------------------------------


            //鼠标右键处理(结束)--------------------------------------------------------    
        }  
        frame.repaint();              
    }

    //鼠标移动
    public void mouseMoved(MouseEvent e)
    {
        //鼠标位置
        mx=e.getX();
        my=e.getY();
        //鼠标左键处理(在下面)-----------------------------------------------------


        //鼠标左键处理(结束)--------------------------------------------------------        
        frame.repaint();
    }

    public void keyPressed(KeyEvent evt)
    {
        //键盘处理
        switch(evt.getKeyCode())
        {    
            case KeyEvent.VK_ENTER:
                timerThread = new Thread(this);
                timerThread.start();
                start = true;
                break;
            case KeyEvent.VK_ESCAPE:
                start = false;
                System.exit(1);
                break;
            case KeyEvent.VK_LEFT:
                //键盘左箭头处理(在下面)-----------------------------------------------------


                //键盘左箭头处理(结束)--------------------------------------------------------        
                break;
            case KeyEvent.VK_RIGHT:
                //键盘右箭头处理(在下面)-----------------------------------------------------


                //键盘右箭头处理(结束)--------------------------------------------------------        
                break;
            case KeyEvent.VK_DOWN:
                //键盘下箭头处理(在下面)-----------------------------------------------------


                //键盘下箭头处理(结束)--------------------------------------------------------        
                break;
            case KeyEvent.VK_UP:
                //键盘上箭头处理(在下面)-----------------------------------------------------


                //键盘上箭头处理(结束)--------------------------------------------------------        
                break;                
        }

        frame.repaint();
    }

    public void run()
    {
        while(true)
        {
            try
            {
                //定时时间间隔  timerThread.sleep(毫秒);
                timerThread.sleep(100);
            }
            catch (InterruptedException e)
            {  
                e.printStackTrace();
            }
            
            if(start==false)
                return;
            //定时处理(在下面)-----------------------------------------------------


            //定时处理(结束)--------------------------------------------------------                            
            frame.repaint();
        }
    }

    class Screen extends JComponent
    {   
        public void paint(Graphics g)
        {
            Graphics2D g2d = (Graphics2D)g;
            //画图处理(在下面)-----------------------------------------------------
            
            //画图处理(结束)--------------------------------------------------------                
        }
    }

    public static void main(String[] args)
    {
         new Game();
    }
};




以上程序中  画图处理下面的代码应该怎么写   (定是代码自己会)
搜索更多相关主题的帖子: 代码 制作 
2008-08-31 18:31
快速回复:我想制作一个 可以来回移动的圆 会的帮下忙写下代码
数据加载中...
 
   



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

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