java - How to display a picture on JFrame? -


i'm doing exercise i'm supposed write program simulates race between 2 cars.

i've created jframe , added 2 rectangles supposed tracks.

but can't insert cars. have googled , tried solutions doesn not work out.

here 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 , how can add 2 pictures?

thanks

this how add image jframe

frame.add(new jlabel(new imageicon("path/to/your/image.png"))); 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -