trying to get both cars to show up in jwindow

jrb47
jrb47 used Ask the Experts™
on
I am trying to complete a project.
I have the code working accept for getting both vehicles to show up in the component window.

error
 ----jGRASP exec: javac -g D:\CEN5990\Projects\New Folder\CarMover.java

CarMover.java:16: cannot find symbol
symbol  : class GridLayout
location: class CarMover
                        windowFrame.getContentPane().setLayout(new GridLayout(2, 2));
                                                                           ^
1 error

 ----jGRASP wedge2: exit code for process is 1.
 ----jGRASP: operation complet
import javax.swing.JFrame;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import java.awt.Color;
import java.awt.event.ActionEvent;
import javax.swing.JComponent;
 
public class CarMover {
 
      public static void main(String[] args) {
 
            Car someCar = new Car(0, 0, Color.RED);
            Car someCar2 = new Car(100, 0, Color.BLUE);
 
            JFrame windowFrame = new JFrame();	
				windowFrame.getContentPane().setLayout(new GridLayout(2, 2));
 
            final int WINDOWFRAMEWIDTH = 300;
            final int WINDOWFRAMEHEIGHT = 400;
            final int FRAMEDELAY = 50; // milliseconds
 
            windowFrame.setSize(WINDOWFRAMEWIDTH, WINDOWFRAMEHEIGHT);
            windowFrame.setTitle("Car Animation");
            windowFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
            CarComponent component = new CarComponent(someCar);
            CarComponent component2 = new CarComponent(someCar2);
            windowFrame.add(component);
            windowFrame.add(component2);
            windowFrame.setVisible(true);
							
				
            Timer carTimer = new Timer(FRAMEDELAY, new TimerListener(someCar, component));
            carTimer.start();
				Timer carTimer2 = new Timer(FRAMEDELAY, new TimerListener(someCar2, component2));
            carTimer2.start();
 
 
      }
 
 
      static class TimerListener implements ActionListener {
 
            Car car;
            JComponent jc;
 
            public TimerListener(Car c, JComponent j)
				{
                  car = c;
                  jc = j;
            }
 
            public void actionPerformed(ActionEvent event) {
                  if (car.getX() > jc.getWidth() || car.getY() > jc.getHeight()) {
                        car.move(0, 0);
                  } else {
                        car.translate(0, 1);
                  }
 
                  jc.repaint();
            }
 
      }
}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Java Developer
Top Expert 2010
Commented:
add the import

import java.awt.GridLayout;

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial