java - How to put an image in the background of a window -


i'm done hangman java code. want add picture in background though.(nightsky.png) how do in paint graphics method? created imageicon in beginning.

public hangmanrevised() {     setsize(600,400);     setlocationrelativeto(null);     setdefaultcloseoperation(exit_on_close);     setlayout(new flowlayout());      imageicon background = new imageicon("nightsky.png");     letter = new textfield();     jlabel label = new jlabel("pick letter");     button = new button("enter");     add(label);     add(button);     add(letter);      button.addactionlistener(this);      creategame();  }   public void paint(graphics g) {     super.paint(g);     g.drawimage(background, 0, 156, color.green, button); } 

if painting image @ actual size, there no need custom painting.

as has been suggested add icon jlabel , add label frame (or panel). if want image appear @ certion position within label, add emptyborder label.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -