java - JPanel Wont Load Image -


so can't figure out why can't load image jpanel....the code kinda long, have commented, should simple deduce whats going on. can help? have tried removing background color , did not seem @ (other remove background color)

edit

i managed fix error drawscene method being called in class wasn't added to, , show there error loading image...i'm not entirely sure why though. image using if wants try running program themselves. have added in package right underneath window.java file.


enter image description here

import java.awt.borderlayout; import java.awt.color; import java.awt.dimension; import java.awt.graphics; import java.awt.image; import java.awt.event.actionevent; import java.awt.event.actionlistener; import java.net.url;  import javax.imageio.imageio; import javax.swing.jframe; import javax.swing.jmenu; import javax.swing.jmenubar; import javax.swing.jmenuitem; import javax.swing.jpanel; ///  ///window class begins  ///  public class window extends jpanel{      //instance variables     tools tool = new tools();     gamescreen game = new gamescreen();     scene scene = new scene();      //all other variable initialization things     private static final long serialversionuid = 1l;       public window(){         //sets layout class         this.setlayout(new borderlayout());          //adding things class         this.add(game,borderlayout.center);           //sets background colors panels         this.game.setbackground(color.black);      }      public static void main(string args[]){         jframe frame = new jframe();         window window = new window();         frame.setsize(new dimension(800,600));         frame.setextendedstate(jframe.maximized_both);         frame.setdefaultcloseoperation(jframe.exit_on_close);         frame.setvisible(true);         frame.setjmenubar(tools.bar);         frame.add(window);         frame.pack();         frame.setlocationrelativeto(null);     }      public void paintcomponent(graphics g){        }      ///  // toolbar class begins      ////      public static class tools extends jpanel implements actionlistener{          private static final long serialversionuid = 1l;          jpanel panel = new jpanel();         public static jmenubar bar = new jmenubar();         jmenu file = new jmenu("file");         jmenuitem exit = new jmenuitem("exit");          @suppresswarnings("static-access")         public tools(){              //set layouts             this.panel.setlayout(new borderlayout());              //add bar              this.bar.add(file,borderlayout.west);               //add things inside of bar             this.file.add(this.exit);             this.panel.add(this.bar);              //add panels             this.add(panel);              //action commands              this.exit.setactioncommand("exit");              //add action listeners             this.exit.addactionlistener(this);         }          @override         public void actionperformed(actionevent e) {              if (e.getactioncommand() == "exit"){                 system.out.println("closed");                 system.exit(0);             }          }      }      /////      //gamescreen class begins      ////     public class gamescreen extends jpanel implements actionlistener{          private static final long serialversionuid = 1l;          //instance variables          scene scene = new scene();           //jpanel variables          jpanel screen =  new jpanel(new borderlayout());          public gamescreen(){              //sets class layout               //adding panels             this.add(screen);              //setting color             this.screen.setbackground(new color(0,0,0));              //adding things panels             this.screen.add(scene);           }           @override         public void actionperformed(actionevent e) {           }          public void paintcomponent(graphics g){             scene.drawscence(g, "backgound.jepg", 0, 0, 600, 600);         }      }       public class scene extends jpanel{           public scene(){          }          public void drawscence(graphics g,string location,int x,int y,int width,int height){             try{                  url url = this.getclass().getresource(location);                  image image = imageio.read(url);                  g.drawimage(image, x, y, width, height, null);             }catch (exception e){                 system.out.println("unable load image.");             }          }     } } 


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -