Question: In java programmng, the code below draws 2 car.(I didnot put car class and driver bcs they are unnecessary for my queston) How to move
In java programmng, the code below draws 2 car.(I didnot put car class and driver bcs they are unnecessary for my queston) How to move these cars by changing this class ? car1 should move to the right and car2 to the left.
import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JComponent;
/** This component draws two car shapes. */ public class CarComponent extends JComponent { public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g;
Car car1 = new Car(0, 0); int x = getWidth() - 60; int y = getHeight() - 30;
Car car2 = new Car(x, y);
car1.draw(g2); car2.draw(g2); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
