我想制作一个 可以来回移动的圆 会的帮下忙写下代码
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();
}
};
以上程序中 画图处理下面的代码应该怎么写 (定是代码自己会)