Skip to main content

Thread: Netbeans displays Imgaes but Eclipse doesn't? (code included)


code:
public class gameapplet extends japplet {        private paintsurface canvas;        @override      public void init() {          this.setsize(650, 450);          canvas = new paintsurface();          this.add(canvas);          thread t = new animationthread(this);          t.start();      }      }    public class paintsurface extends jcomponent {        @override      public void paint(graphics g) {          graphics2d g2d = (graphics2d)g;              card janbright = new card("images/kintengu_01c.png", 250, 10);          card janpoemscr = new card("images/kintengu_01d.png", 84, 10);          g2d.setcolor(color.black);          g2d.drawimage(janbright.img, 300, 10, null);          g2d.drawimage(janpoemscr.img, 84, 10, null);      }  }    public class card {      image img;      int xpos;      int ypos;        public card(string img, int xpos, int ypos) {          this.img = getimage(img);          this.xpos = xpos;          this.ypos = ypos;      }            public image getimage(string img) {          toolkit toolkit = toolkit.getdefaulttoolkit();          return toolkit.getimage(img);      }    }    public class animationthread extends thread {        japplet c;        public animationthread(japplet c) {          this.c = c;      }        @override      public void run() {          while(true) {              c.repaint();              try {                  thread.sleep(20);              } catch(interruptedexception e) {              }          }      }  }
if need more info, please ask.

suggestions.

for applet find images, should always:
  • include images in .jar file
  • load them using relative path using class.getresource(...) functions.

otherwise whether images found or not depends on "current path" during execution, shouldn't rely on being set "correctly".


Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk Netbeans displays Imgaes but Eclipse doesn't? (code included)


Ubuntu

Comments