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 :

  1. first of copy background image , paste in src of code

  2. than set layout borderlayout this:

setlayout(new borderlayout());

  1. now add code:

setcontentpane(new jlabel new imageicon(getclass().getresource("image.jpg"))));

note: add image name here "image.jpg"

  1. now set layout flow layout this

setlayout(new flowlayout());

  1. and write code here

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -