/* * Animates 3 identical images to seem like a single one, and Uses a Queue * System to seem like the image is going into a loop. */ @Override public void update(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); if ((loopImage1.getImgIcon().getImage().getWidth(this) > 0) && (loopImage1.getImgIcon().getImage().getHeight(this) > 0)) { // Draw Left Image g2d.drawImage( loopImage2.getImgIcon().getImage(), Xpos2 + border, Ypos, imageWidth, imageHeight, this); // Draw setCenterToFrame Image g2d.drawImage(loopImage1.getImgIcon().getImage(), Xpos, Ypos, imageWidth, imageHeight, this); // Draw Right Image g2d.drawImage( loopImage3.getImgIcon().getImage(), Xpos3 - border, Ypos, imageWidth, imageHeight, this); } animate(); g2d.dispose(); }
public void setCenterToFrame(JFrame frame) { Xpos = frame.getSize().width / 10 + 1; loopImage2.setVisible(false); loopImage3.setVisible(false); Xpos2 = Xpos2 + loopImage2.getImgWidth(); Xpos3 = Xpos3 - loopImage3.getImgWidth(); }
public boolean isCentered() { if (Xpos == 0 || Xpos2 == 0 - loopImage2.getImgIcon().getIconWidth() || Xpos3 == 0 + loopImage3.getImgIcon().getIconWidth()) { isCentered = true; } else { isCentered = false; } return isCentered; }
private void animate() { // move X cordinate to animate if (!pause) { Xpos++; Xpos2++; Xpos3++; } // If Right image is off screen place it behind Left Image if (Xpos3 >= this.getWidth()) { Xpos3 = Xpos2 - loopImage3.getImgIcon().getIconWidth() + block; } // iF setCenterToFrame Image off screen place behind else if (Xpos >= this.getWidth()) { Xpos = Xpos3 - loopImage3.getImgIcon().getIconWidth(); } // if Left Image off screen place behind setCenterToFrame Image else if (Xpos2 >= this.getWidth()) { Xpos2 = Xpos - loopImage3.getImgIcon().getIconWidth(); } }
public AScrollingImage(String URL, int ImageWidth, int ImageHeight) { super(true); imgURL = URL; loopImage1 = new AImage(imgURL); loopImage2 = new AImage(imgURL); loopImage3 = new AImage(imgURL); if (ImageWidth != 0 && ImageHeight != 0) { loopImage1.setImg( new ImageIcon( AImage.resizeImage(loopImage1.getImgIcon().getImage(), ImageWidth, ImageHeight))); loopImage2.setImg( new ImageIcon( AImage.resizeImage(loopImage1.getImgIcon().getImage(), ImageWidth, ImageHeight))); loopImage3.setImg( new ImageIcon( AImage.resizeImage(loopImage3.getImgIcon().getImage(), ImageWidth, ImageHeight))); } imageHeight = loopImage1.getImgIcon().getIconHeight(); imageWidth = loopImage1.getImgIcon().getIconWidth(); Xpos2 = 0 - loopImage2.getImgIcon().getIconWidth(); Xpos3 = 0 + loopImage3.getImgIcon().getIconWidth(); Xpos = 0; setOpaque(false); }