java - Putting an image in the background -
this question has answer here:
- add background image panel 2 answers
i trying put image background. when run code, screen nothing shows , screen 2 buttons , yellow background. how replace yellow , put in image want??
import java.awt.borderlayout; import java.awt.color; import java.awt.dimension; import java.awt.image.bufferedimage; import java.io.file; import java.io.ioexception; import javax.imageio.imageio; import javax.swing.jbutton; import javax.swing.jframe; import javax.swing.jlabel; import javax.swing.jpanel; public class gameframe extends jframe { public bufferedimage image; public jframe gameframe; public jpanel panel; public jbutton b1; public jbutton b2; public jlabel lab; public gameframe() { //setting gameframe gameframe = new jframe("poop man"); gameframe.setvisible(true); gameframe.setsize(1350, 1000); gameframe.setdefaultcloseoperation(jframe.exit_on_close); panel = new jpanel(); panel.setbackground(color.yellow); //buttons panel.setlayout(null); b1 = new jbutton("controls"); b2 = new jbutton("start"); b1.setbounds(500, 200, 150, 150); b2.setbounds(500, 400, 150, 150); b1.setpreferredsize(new dimension(50, 50)); b2.setpreferredsize(new dimension(30, 50)); panel.add(b1, borderlayout.south); panel.add(b2, borderlayout.south); gameframe.add(panel); gameframe.repaint(); } public void imagepanel() { try { image = imageio.read(new file("unnamed")); } catch (ioexception ex) { } } public bufferedimage getimg() { return image; } }
its not straight forward make nice. take @ background panel https://tips4java.wordpress.com/2008/10/12/background-panel/
Comments
Post a Comment