0
import java.awt.*;
import java.awt.event.*;
import javax.swing.JApplet;

public class CarApplet 
{
 private Image carLeft = null;
 private Image carRight = null;
 private Image carUp = null;
 private Image carDown = null;
 private Image carImage = null;
 private int direction = -1;
 privte Point carLocation = new Point(25,25);  ?  /*Over here this line 
 private int speed = 10;                                  * gets highlighted and  
                                                             *says semicolon required.//
 public void setCar(Image carImage)
 {
     this.carImage = carImage;
    }

    public Image getCar()
    {
        return carImage;
    }

    private int getDirection()
    {
        return Direction;
    }

    private void setDirection(int direction)
    {
        this.direction = direction;
    }

    private Point getCarLocation()
    (
    return carLoation
    }

    private void setCarLocation(Point carLocation)
    {
        this.carLocation = carLocation;
    }

    public void paint(Graphics g)
    {
        Image car = getCar();
        if (car == null)
        throw new RuntimeException("Error");
        g.setColor(Color.WHITE);
        g.fillRect(0, 0, getWidth(), getHeight());
        g.drawImage(car, getCarLocation().x, getCarLocation(0.y, this);
    }

    public void init()
    {
        carLeft = getImage(getCodeBase(),"icon/left.gif");
        carRight = getImage(getCodeBase(),"icon/right.gif");
        carUp = getImage(getCodeBase(),"icon/up.gif");
        carDown = getImage(getCodeBase(),"icon/down.gif");

        setCar(carRight);
        addKeyListner(new KeyAdapter(0
        {
            public void keyPressed(KeyEvent e)
            {
                int locationX = getCarLocation().x;
                int locationY = getCarLocation().Y;

                int key = e.getKeyCode();
                switch(key)
                {
                    case KeyEvent.VK_up:
                    if (getDirection() != key)
                    setCar(carUp);
                    locationY -= speed;
               break;
                    case KeyEvent.VK_DOWN:
                    if (getDirection() != key)
                    setCar(carDown);
                    locationY += speed;
               break;
                    case KeyEvent.VK_DOWN:
                    if (getDirection() != key)
                    setCar(carLeft);
                    locationX -= speed;
               break;     
                    case KeyEvent.VK_DOWN:
                    if (getDirection() != key)
                    setCar(carRight);
                    locationX += speed;
               break;
               default:
               break;
            }
            setDirection(key);
            setCarLocation(new Point(locationX,locationY));
            repaint();
        }});
    }
}

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Katana24
0

start quote:

import java.awt.*;
import java.awt.event.*;
import javax.swing.JApplet;

public class CarApplet 
{
 private Image carLeft = null;
 private Image carRight = null;
 private Image carUp = null;
 private Image carDown = null;
 private Image carImage = null;
 private int direction = -1;
 privte Point carLocation = new Point(25,25);  ?  /*Over here this line 
 private int speed = 10;                                  * gets highlighted and  
                                                             *says semicolon required.//
 public void setCar(Image carImage)
 {
     this.carImage = carImage;
    }

    public Image getCar()
    {
        return carImage;
    }

    private int getDirection()
    {
        return Direction;
    }

    private void setDirection(int direction)
    {
        this.direction = direction;
    }

    private Point getCarLocation()
    (
    return carLoation
    }

    private void setCarLocation(Point carLocation)
    {
        this.carLocation = carLocation;
    }

    public void paint(Graphics g)
    {
        Image car = getCar();
        if (car == null)
        throw new RuntimeException("Error");
        g.setColor(Color.WHITE);
        g.fillRect(0, 0, getWidth(), getHeight());
        g.drawImage(car, getCarLocation().x, getCarLocation(0.y, this);
    }

    public void init()
    {
        carLeft = getImage(getCodeBase(),"icon/left.gif");
        carRight = getImage(getCodeBase(),"icon/right.gif");
        carUp = getImage(getCodeBase(),"icon/up.gif");
        carDown = getImage(getCodeBase(),"icon/down.gif");

        setCar(carRight);
        addKeyListner(new KeyAdapter(0
        {
            public void keyPressed(KeyEvent e)
            {
                int locationX = getCarLocation().x;
                int locationY = getCarLocation().Y;

                int key = e.getKeyCode();
                switch(key)
                {
                    case KeyEvent.VK_up:
                    if (getDirection() != key)
                    setCar(carUp);
                    locationY -= speed;
               break;
                    case KeyEvent.VK_DOWN:
                    if (getDirection() != key)
                    setCar(carDown);
                    locationY += speed;
               break;
                    case KeyEvent.VK_DOWN:
                    if (getDirection() != key)
                    setCar(carLeft);
                    locationX -= speed;
               break;     
                    case KeyEvent.VK_DOWN:
                    if (getDirection() != key)
                    setCar(carRight);
                    locationX += speed;
               break;
               default:
               break;
            }
            setDirection(key);
            setCarLocation(new Point(locationX,locationY));
            repaint();
        }});
    }
}

end quote.

So wat exactly is your problem? Outline it and put your code into the brackets

Edited by mike_2000_17: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.