Movement


Get this applet running. You're on your own for the paint method, but the rest of this applet is provided: import java.awt.*; import java.applet.*; import java.awt.event.*; public class car extends Applet{ int x; boolean rt; public void init(){ setBackground(Color.black); rt=true; requestFocus(); this.addKeyListener(new KeyAdapter(){ public void keyPressed(KeyEvent k){ erase(); if(rt){ x+=5; if(x>190) rt=false; } else{ x-=5; if(x<10) rt=true; } repaint(); } }); } public void erase(){ //This method erases the previously drawn car Graphics g = getGraphics(); g.setColor(Color.black); g.fillRect(x-5, 40, 50, 50); }