java - Printing BufferedImage on JPanel -


i trying display bufferedimage onto jpanel when run program doesn't display anything.

i imagine problem creation of bufferedimage but, limited understanding of java, have no idea problem might be. appreciate more information paintcomponent method (what super.paintcomponent(g) mean?)

main.java

public class main {  public static void main (string[] args) {   window.windowmake("this window");  } } 

window.java

import java.awt.image.bufferedimage; import java.awt.graphics; import java.awt.image; import javax.swing.jcomponent; import javax.swing.jframe; import javax.imageio.imageio;  public class window extends jframe {  public static void windowmake(string title) {   jframe jf = new jframe();   jf.setdefaultcloseoperation(jframe.exit_on_close);   jf.setsize(300,300);   jf.setvisible(true);   jf.settitle(title);   jf.add(new paint());  } } 

paint.java

import java.io.ioexception; import java.io.file; import java.awt.image.bufferedimage; import java.awt.graphics; import javax.swing.jpanel; import javax.swing.jframe; import javax.imageio.imageio;  public class paint extends jpanel {  bufferedimage sprite = new  bufferedimage(60,60,bufferedimage.type_int_argb);   public void createbufimg() {   try {    sprite = imageio.read(new file("/images/scene.png"));    system.out.println("file read");   } catch (ioexception e) {    system.out.println("could not read image");   }  }   @override   public void paintcomponent(graphics g) {   super.paintcomponent(g);   g.drawimage(sprite,20,20,this);  } } 

add constructor class paint creates sprite , program show image.

public paint() {     super();     createbufimg(); } 

also, should not calling classes same names classes or methods in swing, gets confusing. don't make classes called main, panel , window.

what super.paintcomponent(g) mean

it calls paintcomponent method of super class, ie class extending (jpanel in instance). suggest things on internet painting in swing more details.


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -