Adding few images in Java JFrame -
i'm making 2d game. have background , character images. both of them .gif files. layout or need use set background behind character? tried ways either they're in row or nothing happens.
i adding pictures that:
url url = main.class.getresource("images/main.gif"); imageicon imageicon = new imageicon(url); jlabel background = new jlabel(imageicon);
code background :
first of copy background image , paste in src of code
than set layout borderlayout this:
setlayout(new borderlayout());
- now add code:
setcontentpane(new jlabel new imageicon(getclass().getresource("image.jpg"))));
note: add image name here "image.jpg"
- now set layout flow layout this
setlayout(new flowlayout());
- and write code here
Comments
Post a Comment