/** * This method paints the canvas. * * @param g Graphics: this is the graphical environment. */ public void paint(Graphics g) { Toolkit toolkit = Toolkit.getDefaultToolkit(); URL url = getClass().getResource("desenvolupament.png"); Image image = toolkit.getImage(url); MediaTracker mediaTracker = new MediaTracker(this); mediaTracker.addImage(image, 0); try { mediaTracker.waitForAll(); if (mediaTracker.checkAll()) { g.drawImage(image, 0, 0, this); } } catch (InterruptedException e) { System.out.println("No puc amb la imatge!"); } }
/** * A check that indicates images loaded. * * @return true if ALL images are loaded, or something went horribly wrong. false if loading is in * progress. */ public boolean isImagesLoaded() { return tracker.checkAll(); }