I'm doing this exercise where I'm supposed to write a program that simulates a race between two cars.
I've created a JFrame
and added two rectangles that are supposed to be the tracks.
But I can't insert the cars. I have googled and tried some solutions but it just doesn not work out.
Here is my code.
public class Race extends JComponent {
private ImageIcon image;
public void paint(Graphics g) {
g.setColor(Color.GRAY);
g.fill3DRect(30, 150, 530, 55,true);
g.setColor(Color.GRAY);
g.fill3DRect(30, 250, 530, 55, true);
g.setColor(Color.BLACK);
g.fill3DRect(90, 130, 12, 189, true);
}
public static void main(String[] a) {
JFrame window = new JFrame();
window.setPreferredSize(new Dimension(600, 400));
window.getContentPane().setBackground(Color.GREEN);
window.setResizable(false);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.getContentPane().add(new Race());
window.pack();
window.setVisible(true);
}
}
Where and how can I add two pictures?
Thanks