import java.awt.*; import java.applet.*; public final class ScrollImage extends Applet { private int width,height; private Image offI,img; private Graphics offG; private MediaTracker imageTracker; private Point pointInitial = new Point(0, 0); private int posImageX = 0, posImageY = 0; int tailleImageX = 540; int tailleImageY = 380; int positionInitialeX = 0; int positionInitialeY = 0; Object frame; public void init() { setBackground(new Color(255, 200, 50)); Integer intObj; String s = new String(""); s = getParameter("Image"); System.out.println(s); img = getImage(getCodeBase(),s); imageTracker = new MediaTracker(this); imageTracker.addImage(img,0); try { imageTracker.waitForID(0); } catch(InterruptedException e){} tailleImageX = img.getWidth(this); tailleImageY = img.getHeight(this); System.out.println(tailleImageX + "," + tailleImageY); try { intObj = new Integer(getParameter("width")); width = intObj.intValue(); } catch (Exception e) { width = 200; } try { intObj = new Integer(getParameter("height")); height = intObj.intValue(); } catch (Exception e) { height = 200; } offI = createImage(tailleImageX, tailleImageY); offG = offI.getGraphics(); frame = getParent(); while(! (frame instanceof Frame)) frame = ((Component) frame).getParent (); repaint(); } public void start() { offG.drawImage(img,0,0,this); repaint(); } public final boolean mouseDown(Event evt, int x, int y) { pointInitial = new Point(x, y); ((Frame) frame).setCursor(Frame.HAND_CURSOR); positionInitialeX = posImageX; positionInitialeY = posImageY; return true; } public final boolean mouseDrag(Event evt, int x, int y) { posImageX = positionInitialeX - (pointInitial.x - x); posImageY = positionInitialeY - (pointInitial.y - y); repaint(); return true; } public final boolean mouseUp(Event evt, int x, int y) { ((Frame) frame).setCursor(Frame.DEFAULT_CURSOR); return true; } public final void update(Graphics g) { paint(g); } public final void paint(Graphics g) { if (posImageX < width - tailleImageX) posImageX = width - tailleImageX; if (posImageY < height - tailleImageY) posImageY = height - tailleImageY; if (posImageX > 0) posImageX = 0; if (posImageY > 0) posImageY = 0; g.drawImage(offI,posImageX,posImageY,this); } }