How to move image in Java Awt.

Hi ,
I am developing a simple application using Java awt.
I have created a application which displays a image. now i want it to move automatically using a timer or something.
How can i do it. if i have to change the x and y position of the image in which function should i do it?
Which is the function which is called for every frame?
Thanks
Glen.

public void paint(Graphics g)?
Are you making a game by any chance?

Similar Messages

  • How can I create a java.awt.Image from ...

    Hi all,
    How can I create a java.awt.Image from a drawing on a JPanel?
    Thanks.

    JPanel p;
    BufferedImage image =
        new BufferedImage(p.getWidth(), p.getHeight, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = image.createGraphics();
    p.paint(g);
    g.dispose();

  • Display image in java.awt.List

    hello guys,
    How i can display image in java.awt.List means listbox. give me sample code. if you have
    Waiting for your favorable reply.
    Regards,
    Bhavesh Kharwa

    java.awt.List you can not.
    javax.swing.JLast you can.

  • How to resize image using java imageio

    Hello ,
    I want to know how to resize image using java imageio.
    I dont want to use java awt because i am writing a web application.
    help is very much needed
    thank you.

    Just use an AffineTransform !
    Its much easier

  • How to improve performance of java.awt.choice

    Hi!
    In my GUI I'm using a java.awt.choice. The problem is, when my app starts this choice is filled with lots of values with add(...).
    This takes quite a long time. I've already set the choice invisible before the filling, so a little bit performance is gained there.
    Is there any other way to tune this choice?
    Thank you!

    Try to fill the choice before adding it to the container

  • How to move images from Picasa to Lightroom 5 on a mac?

    How to import images from Picasa to Lightroom 5 on a mac?

    Hi, lnmyers,
    I have thousands of pictures stored in Picasa, all of which are stored in my Picasa Web Albums. They are no longer in a directory on my hard-drive, that particular hard-drive having died ages ago. Thank goodness I uploaded them to Picasa's cloud before the hard-drive died. Should that ever darken, I am in trouble. I digress. I downloaded the pictures I wanted from Picasa Web Albums to my new external hard-drive that I set up and attached to my mac. For example:  I had a an album called "California 2013" stored in the Picasa cloud. I downloaded the entire album to a folder on my Seagate external drive that I call Lightroom within which I have a folder called California 2013. It took about twenty minutes to get them all (300+ photos). Then, I pointed LR to the California 2013 folder on the Seagate external drive when I wanted to catalogue the pictures into LR. I did not worry about metadata; I took whatever came with the pictures and didn't worry about it. I added copyright, keywords, and ownership info with LR. 
    I hope that helps.

  • Need a little help: How to move images in a video?

    Hi!
    I've been searching this throughout the whole forum but was not able to find this. I probably do not have the right terms as I'm not really familiar with Premiere Pro yet. I hope someone can explain me how to do the following: I have a video fragment from a television program and I need added an image on top of this video for a project from university. Now what I need is, that this image moves a long in the scene. I replaced a milk can with another one as you can see in the example, now as the camera moves, the milkcan needs to move along so it will stay at the same place on the table. Is this possible?
    Many thanks in advance!

    To add to the advice from Ann, if you visit the Creative Cow website there are a mass of After Effects video tutorials where you will find one that is specifically for your task.

  • How to move images, presets, and catalog now in Lightroom 5.7 on my old windows computer to my new windows computer. Need detailed instructions.

    I recently purchased a new computer which is running windows 8.1.  My old computer is running windows 7 with lightroom 5.7 on it.  I have installed the software for Lightroom 5.7.1 on my new computer.  How do I transfer or move my images, presets, and catalog from my old computer to the new one?  I need detailed instructions.

    http://tv.adobe.com/watch/the-complete-picture-with-julieanne-kost/how-to-migrate-lr-to-an other-computer/

  • How to move image from one hard drive to another - T41

    Hi All
    I have a T41 which has a 30GB hard drive, over the time I have installed quite a few programs which I don't have the cd's for to reinstall. Now that I am almost out of space I need to swap my present Hard Drive with another one. I already bought a 60GB HD for the laptop but I don't want to just swap it, what I want to do is make an image of the existing HD and past it in the new HD and then swap the HD so that I have everything from my previous HD.
    Can I do this with Ghost 2003 or maybe with anyother ghost app. Also what if I just make a backup of the registry and system state through windows backup tools then install windows XP in the new HD and then restore the restore the system state and registry from the backup. In this wall I will loose the hidden partition.
    Please advice whether I can image of the current HD and then move it to the new HD.
    Thanks in advance 

    Thanks for the responses for far, I really appriciate it.
    Ok, I have two question for two response I received:
    To infocatchjp:
    1. I didn't find any connector for "ThinkPad 2nd HDD Adapter for Ultrabay Slim".
    2. Rescue and recovey is a windows tool or built in IBM tool.
    3. Would it tranfer the program as well and also the hidden partition for the laptop.
    To stbigham:
    I went to the website for the given software and checked out its feature. My only question is would the software transfer the existing and hidden partition when it is moved to the new HD.
    thank you both for your support. Hope to hear from you soon.
    Haydes 

  • Nokia 7373-how to move images etc to phone memory ...

    Hi Ive just bought a cool nokia 7373 and after bluetoothing all my images/videos/music from my old samsung Im having trouble sorting them all into images/videos/music folders.
    They are all in my memory card muddled up just now but if I mark all my pics and then go to move marked then send to Images folder its saying not enough memory?
    Why is this does anyone know as I thought I had more memory on the nokia than my samsung?
    Thanks in advance
    Laura.x

    Hi Jake,
    If you do the following steps, it should work!
    - Go to "People"
    - Click on "Phonebook" at the top so that the dropdown opens and shows you what it populating the contacts in your phone.
    - Uncheck everything but Google. (That means un-check Sim Card, Phone, Facebook, and even Google+)
    Once you do this, when you add new contacts, it should default to Google. The only other option is to "train" yourself to select your Google account rather than phone (under "Contact Type") when adding new contacts.

  • How to send images through java or RMI.?

    Hello,
    I have a problem with RMI. I had created a canvas on which you can draw anything then when clicking send button this drawing should be reach to another client(s). so please guide me how to do it. and also please give some code if possible.
    thanks very much.
    umesh m joshi

    Hello RoopaSri:
    Umm, I don't think it will help in his case. He means to send a drawing from a canvas and not a image file.So that is back to his question
    hello umjosh ,
    you can get an image object from the Graphics class and RMI the bytes gotten from the image object. U can find in this forum on how to save the canvas. instead of saving, u can send the bytes.
    eg Imageicon imgIcon=new Imageicon("imagefile.jpg");
    and send it to the remote object. Use
    ImageIcon.getImage can used to exrtract the image.
    Hope this helped.
    Regards,
    Roopa Vittal
    developer technical Support
    SUN Microsystems.

  • How to add images into a java application (not applet)

    Hello,
    I am new in java programming. I would like to know how to add images into a java application (not an applet). If i could get an standard example about how to add a image to a java application, I would apreciated it. Any help will be greatly apreciated.
    Thank you,
    Oscar

    Your' better off looking in the java 2d forum.
    package images;
    import java.awt.*;
    import java.awt.image.*;
    import java.io.FileInputStream;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    /** * LogoImage is a class that is used to load images into the program */
    public class LogoImage extends JPanel {
         private BufferedImage image;
         private int factor = 1; /** Creates a new instance of ImagePanel */
         public LogoImage() {
              this(new Dimension(600, 50));
         public LogoImage(Dimension sz) {
              //setBackground(Color.green);      
              setPreferredSize(sz);
         public void setImage(BufferedImage im) {
              image = im;
              if (im != null) {
                   setPreferredSize(
                        new Dimension(image.getWidth(), image.getHeight()));
              } else {
                   setPreferredSize(new Dimension(200, 200));
         public void setImageSizeFactor(int factor) {
              this.factor = factor;
         public void paintComponent(Graphics g) {
              super.paintComponent(g);
              //paint background 
              Graphics2D g2D = (Graphics2D) g;
              //Draw image at its natural size first. 
              if (image != null) {
                   g2D.drawImage(image, null, 0, 0);
         public static LogoImage createImage(String filename) { /* Stream the logo gif file into an image object */
              LogoImage logoImage = new LogoImage();
              BufferedImage image;
              try {
                   FileInputStream fileInput =
                        new FileInputStream("images/" + filename);
                   image = ImageIO.read(fileInput);
                   logoImage =
                        new LogoImage(
                             new Dimension(image.getWidth(), image.getHeight()));
                   fileInput.close();
                   logoImage.setImage(image);
              } catch (Exception e) {
                   System.err.println(e);
              return logoImage;
         public static void main(String[] args) {
              JFrame jf = new JFrame("testImage");
              Container cp = jf.getContentPane();
              cp.add(LogoImage.createImage("logo.gif"), BorderLayout.CENTER);
              jf.setVisible(true);
              jf.pack();
    }Now you can use this class anywhere in your pgram to add a JPanel

  • How to process images(Zooming) in java

    Hai,
    In our project,i need to provide an option to the end user to zoom the image, i am able to provide options like rotating an image and flipping an image using java image processing API. If anybody has already visited the website http://photo.stamps.com/PhotoStamps/?source=cj00470773, where we can also zoom a photo(they done it using Flash). My requirement is similar to this site.
    I would be greatful if anybody can suggest me about how to zoom images using Java
    Thanks
    PRAMOD.

    Hi,
    You can use AffineTransform to scale an image.
    /Kaj

  • Custom graphics in java.awt.ScrollPane

    Hi all,
    I have to draw a custom created image in a scroll pane. As the image is very large I want to display it in a scroll pane. As parts of the image may change within seconds, and drawing the whole image is very time consuming (several seconds) I want to draw only the part of the image that is currently visible to the user.
    My idea: creating a new class that extends from java.awt.ScrollPane, overwrite the paint(Graphics) method and do the drawings inside. Unfortunately, it does not work. The background of the scoll pane is blue, but it does not show the red box (the current viewport is not shown in red).
    Below please find the source code that I am using:
    package graphics;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.ScrollPane;
    import java.awt.event.AdjustmentEvent;
    public class CMyComponent extends ScrollPane {
         /** <p>Listener to force a component to repaint when a scroll bar changes its
          * position.</p>
         private final class ScrollBarAdjustmentListener implements java.awt.event.AdjustmentListener {
              /** <p>The component to force to repaint.</p> */
              private final Component m_Target;
              /** <p>Default constructor.</p>
               * @param Target The component to force to repaint.
              private ScrollBarAdjustmentListener(Component Target) { m_Target = Target; }
              /** <p>Forces to component to repaint upon adjustment of the scroll bar.</p>
               *  @see java.awt.event.AdjustmentListener#adjustmentValueChanged(java.awt.event.AdjustmentEvent)
              public void adjustmentValueChanged(AdjustmentEvent e) { m_Target.paint(m_Target.getGraphics()); }
         public CMyComponent() {
              // Ensure that the component repaints upon changing of the scroll bars
              ScrollBarAdjustmentListener sbal = new ScrollBarAdjustmentListener(this);
              getHAdjustable().addAdjustmentListener(sbal);
              getVAdjustable().addAdjustmentListener(sbal);
         public void paint(Graphics g) {
              setBackground(Color.BLUE);
              g.setColor(Color.RED);
              g.fillRect(getScrollPosition().x, getScrollPosition().y, getViewportSize().width, getViewportSize().height);
         public final static void main(String[] args) {
              java.awt.Frame f = new java.awt.Frame();
              f.add(new CMyComponent());
              f.pack();
              f.setVisible(true);
    }

    Dear all,
    I used the last days and tried several things. I think now I have a quite good working solution (just one bug remains) and it is very performant. To give others a chance to see what I have done I post the source code of the main class (a canvas drawing and implementing scrolling) here. As soon as the sourceforge project is accepted, I will publish the whole sources at there. Enjoy. And if you have some idea for my last bug in getElementAtPixel(Point), then please tell me.
    package internetrail.graphics.hexgrid;
    import java.awt.Canvas;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Image;
    import java.awt.Point;
    import java.awt.Polygon;
    import java.awt.event.ComponentEvent;
    import java.awt.event.ComponentListener;
    import java.awt.geom.Area;
    import java.awt.image.BufferedImage;
    import java.util.WeakHashMap;
    import java.util.Map;
    /** <p>Hex grid view.</p>
    * <p>Visualizes a {@link IHexGridModel}.</p>
    * @version 0.1, 03.06.2006
    * @author Bjoern Wuest, Germany
    public final class CHexGridView extends Canvas implements ComponentListener, IHexGridElementListener {
         /** <p>Serial version unique identifier.</p> */
         private static final long serialVersionUID = -965902826101261530L;
         /** <p>Instance-constant parameter for the width of a hex grid element.</p> */
         public final int CONST_Width;
         /** <p>Instance-constant parameter for 1/4 of the width of a hex grid element.</p> */
         public final int CONST_Width1fourth;
         /** <p>Instance-constant parameter for 3/4 of the width of a hex grid element.</p> */
         public final int CONST_Width3fourth;
         /** <p>Instance-constant parameter for 1.5 times of the width of a hex grid element.</p> */
         public final int CONST_Width1dot5;
         /** <p>Instance-constant parameter for 4 times of the width of a hex grid element.</p> */
         public final int CONST_Widthquad;
         /** <p>Instance-constant parameter for the height of a hex grid element.</p> */
         public final int CONST_Height;
         /** <p>Instance-constant parameter for 1/2 of the height of a hex grid element.</p> */
         public final int CONST_Heighthalf;
         /** <p>Instance-constant parameter for the double height of a hex grid element.</p> */
         public final int CONST_Heightdouble;
         /** <p>The steepness of a side of the hex grid element (calculated for the upper left arc).</p> */
         public final double CONST_Steepness;
         /** <p>The model of this hex grid </p> */
         private final IHexGridModel m_Model;
         /** <p>A cache for already created images of the hex map.</p> */
         private final Map<Point, Image> m_Cache = new WeakHashMap<Point, Image>();
         /** <p>The graphical area to draw the selection ring around a hex element.</p> */
         private final Area m_SelectionRing;
         /** <p>The image of the selection ring around a hex element.</p> */
         private final BufferedImage m_SelectionRingImage;
         /** <p>The current position of the hex grid in pixels (top left visible corner).</p> */
         private Point m_ScrollPosition = new Point(0, 0);
         /** <p>Flag to define if a grid is shown ({@code true}) or not ({@code false}).</p> */
         private boolean m_ShowGrid = true;
         /** <p>Flag to define if the selected hex grid element should be highlighted ({@code true}) or not ({@code false}).</p> */
         private boolean m_ShowSelected = true;
         /** <p>The offset of hex grid elements shown on the screen, measured in hex grid elements.</p> */
         private Point m_CurrentOffset = new Point(0, 0);
         /** <p>The offset of the image shown on the screen, measured in pixels.</p> */
         private Point m_PixelOffset = new Point(0, 0);
         /** <p>The index of the currently selected hex grid element.</p> */
         private Point m_CurrentSelected = new Point(0, 0);
         /** <p>The width of a buffered pre-calculated image in pixel.</p> */
         private int m_ImageWidth;
         /** <p>The height of a buffered pre-calculated image in pixel.</p> */
         private int m_ImageHeight;
         /** <p>The maximum number of columns of hex grid elements to be shown at once on the screen.</p> */
         private int m_MaxColumn;
         /** <p>The maximum number of rows of hex grid elements to be shown at once on the screen.</p> */
         private int m_MaxRow;
         /** <p>Create a new hex grid view.</p>
          * <p>The hex grid view is bound to a {@link IHexGridModel} and registers at
          * that model to listen for {@link IHexGridElement} updates.</p>
          * @param Model The model backing this view.
         public CHexGridView(IHexGridModel Model) {
              // Set the model
              m_Model = Model;
              CONST_Width = m_Model.getElementsWidth();
              CONST_Height = m_Model.getElementsHeight();
              CONST_Width1fourth = CONST_Width/4;
              CONST_Width3fourth = CONST_Width*3/4;
              CONST_Width1dot5 = CONST_Width*3/2;
              CONST_Heighthalf = CONST_Height/2;
              CONST_Widthquad = CONST_Width*4;
              CONST_Heightdouble = CONST_Height*2;
              CONST_Steepness = (double)CONST_Heighthalf / CONST_Width1fourth;
              m_ImageWidth = getSize().width+CONST_Widthquad;
              m_ImageHeight = getSize().height+CONST_Heightdouble;
              m_MaxColumn = m_ImageWidth / CONST_Width3fourth;
              m_MaxRow = m_ImageHeight / CONST_Height;
              // Register this canvas for various notifications
              m_Model.addElementListener(this);
              addComponentListener(this);
              // Create the selection ring to highlight hex grid elements
              m_SelectionRing = new Area(new Polygon(new int[]{-1, CONST_Width1fourth-1, CONST_Width3fourth+1, CONST_Width+1, CONST_Width3fourth+1, CONST_Width1fourth-1}, new int[]{CONST_Heighthalf, -1, -1, CONST_Heighthalf, CONST_Height+1, CONST_Height+1}, 6));
              m_SelectionRing.subtract(new Area(new Polygon(new int[]{2, CONST_Width1fourth+2, CONST_Width3fourth-2, CONST_Width-2, CONST_Width3fourth-2, CONST_Width1fourth+2}, new int[]{CONST_Heighthalf, 2, 2, CONST_Heighthalf, CONST_Height-2, CONST_Height-2}, 6)));
              m_SelectionRingImage = new BufferedImage(CONST_Width, CONST_Height, BufferedImage.TYPE_INT_ARGB);
              Graphics2D g = m_SelectionRingImage.createGraphics();
              g.setColor(Color.WHITE);
              g.fill(m_SelectionRing);
         @Override public synchronized void paint(Graphics g2) {
              // Caculate the offset of indexes to show
              int offsetX = 2 * (m_ScrollPosition.x / CONST_Width1dot5) - 2;
              int offsetY = (int)(Math.ceil(m_ScrollPosition.y / CONST_Height) - 1);
              m_CurrentOffset = new Point(offsetX, offsetY);
              // Check if the image is in the cache
              Image drawing = m_Cache.get(m_CurrentOffset);
              if (drawing == null) {
                   // The image is not cached, so draw it
                   drawing = new BufferedImage(m_ImageWidth, m_ImageHeight, BufferedImage.TYPE_INT_ARGB);
                   Graphics2D g = ((BufferedImage)drawing).createGraphics();
                   // Draw background
                   g.setColor(Color.BLACK);
                   g.fillRect(0, 0, m_ImageWidth, m_ImageHeight);
                   // Draw the hex grid
                   for (int column = 0; column <= m_MaxColumn; column += 2) {
                        for (int row = 0; row <= m_MaxRow; row++) {
                             // Draw even column
                             IHexGridElement element = m_Model.getElementAt(offsetX + column, offsetY + row);
                             if (element != null) { g.drawImage(element.getImage(m_ShowGrid), (int)(column*(CONST_Width3fourth-0.5)), CONST_Height*row, null); }
                             // Draw odd column
                             element = m_Model.getElementAt(offsetX + column+1, offsetY + row);
                             if (element!= null) { g.drawImage(element.getImage(m_ShowGrid), (int)(column*(CONST_Width3fourth-0.5)+CONST_Width3fourth), CONST_Heighthalf*(row*2+1), null); }
                   // Put the image into the cache
                   m_Cache.put(m_CurrentOffset, drawing);
              // Calculate the position of the image to show
              offsetX = CONST_Width1dot5 + (m_ScrollPosition.x % CONST_Width1dot5);
              offsetY = CONST_Height + (m_ScrollPosition.y % CONST_Height);
              m_PixelOffset = new Point(offsetX, offsetY);
              g2.drawImage(drawing, -offsetX, -offsetY, null);
              // If the selected element should he highlighted, then do so
              if (m_ShowSelected) {
                   // Check if the selected element is on screen
                   if (isElementOnScreen(m_CurrentSelected)) {
                        // Correct vertical offset for odd columns
                        if ((m_CurrentSelected.x % 2 == 1)) { offsetY -= CONST_Heighthalf; }
                        // Draw the selection circle
                        g2.drawImage(m_SelectionRingImage, (m_CurrentSelected.x - m_CurrentOffset.x) * CONST_Width3fourth - offsetX - ((m_CurrentSelected.x + 1) / 2), (m_CurrentSelected.y - m_CurrentOffset.y) * CONST_Height - offsetY, null);
         @Override public synchronized void update(Graphics g) { paint(g); }
         public synchronized void componentResized(ComponentEvent e) {
              // Upon resizing of the component, adjust several pre-calculated values
              m_ImageWidth = getSize().width+CONST_Widthquad;
              m_ImageHeight = getSize().height+CONST_Heightdouble;
              m_MaxColumn = m_ImageWidth / CONST_Width3fourth;
              m_MaxRow = m_ImageHeight / CONST_Height;
              // And flush the cache
              m_Cache.clear();
         public void componentMoved(ComponentEvent e) { /* do nothing */ }
         public void componentShown(ComponentEvent e) { /* do nothing */ }
         public void componentHidden(ComponentEvent e) { /* do nothing */ }
         public synchronized void elementUpdated(IHexGridElement Element) {
              // Clear cache where the element may be contained at
              for (Point p : m_Cache.keySet()) { if (isElementInScope(Element.getIndex(), p, new Point(p.x + m_MaxColumn, p.y + m_MaxRow))) { m_Cache.remove(p); } }
              // Update the currently shown image if the update element is shown, too
              if (isElementOnScreen(Element.getIndex())) { repaint(); }
         /** <p>Returns the model visualized by this grid view.</p>
          * @return The model visualized by this grid view.
         public IHexGridModel getModel() { return m_Model; }
         /** <p>Returns the current selected hex grid element.</p>
          * @return The current selected hex grid element.
         public IHexGridElement getSelected() { return m_Model.getElementAt(m_CurrentSelected.x, m_CurrentSelected.y); }
         /** <p>Sets the current selected hex grid element by its index.</p>
          * <p>If the selected hex grid element should be highlighted and is currently
          * shown on the screen, then this method will {@link #repaint() redraw} this
          * component automatically.</p>
          * @param Index The index of the hex grid element to become the selected one.
          * @throws IllegalArgumentException If the index refers to a non-existing hex
          * grid element.
         public synchronized void setSelected(Point Index) throws IllegalArgumentException {
              // Check that the index is valid
              if ((Index.x < 0) || (Index.y < 0) || (Index.x > m_Model.getXElements()) || (Index.y > m_Model.getYElements())) { throw new IllegalArgumentException("There is no hex grid element with such index."); }
              m_CurrentSelected = Index;
              // If the element is on screen and should be highlighted, then repaint
              if (m_ShowSelected && isElementOnScreen(m_CurrentSelected)) { repaint(); }
         /** <p>Moves the visible elements to the left by the number of pixels.</p>
          * <p>To move the visible elements to the left by one hex grid element, pass
          * {@link #CONST_Width3fourth} as the parameter. The component will
          * automatically {@link #repaint()}.</p>
          * @param Pixels The number of pixels to move to the left.
          * @return The number of pixels moved to the left. This is always between 0
          * and {@code abs(Pixels)}.
         public synchronized int moveLeft(int Pixels) {
              int delta = m_ScrollPosition.x - Math.max(0, m_ScrollPosition.x - Math.max(0, Pixels));
              if (delta != 0) {
                   m_ScrollPosition.x -= delta;
                   repaint();
              return delta;
         /** <p>Moves the visible elements up by the number of pixels.</p>
          * <p>To move the visible elements up by one hex grid element, pass {@link
          * #CONST_Height} as the parameter. The component will automatically {@link
          * #repaint()}.</p>
          * @param Pixels The number of pixels to move up.
          * @return The number of pixels moved up. This is always between 0 and {@code
          * abs(Pixels)}.
         public synchronized int moveUp(int Pixels) {
              int delta = m_ScrollPosition.y - Math.max(0, m_ScrollPosition.y - Math.max(0, Pixels));
              if (delta != 0) {
                   m_ScrollPosition.y -= delta;
                   repaint();
              return delta;
         /** <p>Moves the visible elements to the right by the number of pixels.</p>
          * <p>To move the visible elements to the right by one hex grid element, pass
          * {@link #CONST_Width3fourth} as the parameter. The component will
          * automatically {@link #repaint()}.</p>
          * @param Pixels The number of pixels to move to the right.
          * @return The number of pixels moved to the right. This is always between 0
          * and {@code abs(Pixels)}.
         public synchronized int moveRight(int Pixels) {
              int delta = Math.min(m_Model.getXElements() * CONST_Width3fourth + CONST_Width1fourth - getSize().width, m_ScrollPosition.x + Math.max(0, Pixels)) - m_ScrollPosition.x;
              if (delta != 0) {
                   m_ScrollPosition.x += delta;
                   repaint();
              return delta;
         /** <p>Moves the visible elements down by the number of pixels.</p>
          * <p>To move the visible elements down by one hex grid element, pass {@link
          * #CONST_Height} as the parameter. The component will automatically {@link
          * #repaint()}.</p>
          * @param Pixels The number of pixels to move down.
          * @return The number of pixels moved down. This is always between 0 and
          * {@code abs(Pixels)}.
         public synchronized int moveDown(int Pixels) {
              int delta = Math.min(m_Model.getYElements() * CONST_Height + CONST_Heighthalf - getSize().height, m_ScrollPosition.y + Math.max(0, Pixels)) - m_ScrollPosition.y;
              if (delta != 0) {
                   m_ScrollPosition.y += delta;
                   repaint();
              return delta;
         /** <p>Checks if the hex grid element of the given index is currently
          * displayed on the screen (even just one pixel).</p>
          * <p>The intention of this method is to check if a {@link #repaint()} is
          * necessary or not.</p>
          * @param ElementIndex The index of the element to check.
          * @return {@code true} if the hex grid element of the given index is
          * displayed on the screen, {@code false} if not.
         public synchronized boolean isElementOnScreen(Point ElementIndex) { return isElementInScope(ElementIndex, m_CurrentOffset, new Point(m_CurrentOffset.x + m_MaxColumn, m_CurrentOffset.y + m_MaxRow)); }
         /** <p>Checks if the hex grid element of the given index is within the given
          * indexes.</p>
          * <p>The intention of this method is to check if a {@link #repaint()} is
          * necessary or not.</p>
          * @param ElementIndex The index of the element to check.
          * @param ReferenceIndexLeftTop The left top index of the area to check.
          * @param ReferenceIndexRightBottom The right bottom index of the area to check.
          * @return {@code true} if the hex grid element of the given index is within
          * the given area, {@code false} if not.
         public synchronized boolean isElementInScope(Point ElementIndex, Point ReferenceIndexLeftTop, Point ReferenceIndexRightBottom) { if ((ElementIndex.x >= ReferenceIndexLeftTop.x) && (ElementIndex.x <= ReferenceIndexRightBottom.x) && (ElementIndex.y >= ReferenceIndexLeftTop.y) && (ElementIndex.y <= (ReferenceIndexRightBottom.y))) { return true; } else { return false; } }
         /** <p>Return the {@link IHexGridElement hex grid element} shown at the given
          * pixel on the screen.</p>
          * <p><b>Remark: There seems to be a bug in retrieving the proper element,
          * propably caused by rounding errors and unprecise pixel calculations.</p>
          * @param P The pixel on the screen.
          * @return The {@link IHexGridElement hex grid element} shown at the pixel.
         public synchronized IHexGridElement getElementAtPixel(Point P) {
              // @FIXME Here seems to be some bugs remaining
              int dummy = 0; // Variable for warning to indicate that there is something to do :)
              // Calculate the pixel on the image, not on the screen
              int px = P.x + m_PixelOffset.x;
              int py = P.y + m_PixelOffset.y;
              // Determine the x-index of the column (is maybe decreased by one)
              int x = px / CONST_Width3fourth + m_CurrentOffset.x;
              // If the column is odd, then shift the y-pixel by half element height
              if ((x % 2) == 1) { py -= CONST_Heighthalf; }
              // Determine the y-index of the row (is maybe decreased by one)
              int y = py / CONST_Height + m_CurrentOffset.y;
              // Normative coordinates to a single element
              px -= (x - m_CurrentOffset.x) * CONST_Width3fourth;
              py -= (y - m_CurrentOffset.y) * CONST_Height;
              // Check if the normative pixel is in the first quarter of a column
              if (px < CONST_Width1fourth) {
                   // Adjustments to the index may be necessary
                   if (py < CONST_Heighthalf) {
                        // We are in the upper half of a hex-element
                        double ty = CONST_Heighthalf - CONST_Steepness * px;
                        if (py < ty) { x--; }
                   } else {
                        // We are in the lower half of a hex-element
                        double ty = CONST_Heighthalf + CONST_Steepness * px;
                        if (py > ty) {
                             x--;
                             y++;
              return m_Model.getElementAt(x, y);
    }Ah, just to give you some idea: I use this component to visualize a hex grid map with more than 1 million grid elements. And it works, really fast, and requires less than 10 MByte of memory.

  • Rendering of an 8Bit-tiff with java.awt produces crap

    Hi Folks,
    i do a downsampling of tiff images. The source tiffs are colored 8 Bit greyscale with a 256 color-table. Now i have 2 possibilities to resample with java.awt:
    1. the target-tiff is of 24Bit true color:
    BufferedImage objDownsample = new BufferedImage(iTargetWidth, iTargetHeight, BufferedImage.TYPE_INT_RGB);The result is a perfect looking, but oversized tiff with 16 million colors each pixel.
    2. the target-tiff is of 8Bit like the source-tiff:
    BufferedImage objDownsample = new BufferedImage(iTargetWidth, iTargetHeight, BufferedImage.TYPE_BYTE_INDEXED,(IndexColorModel)image.getColorModel());The result is a small sized tiff image of 8Bit. Problem: it now has visible vertical stripes of two colors (which both composed result the source-color i assume).
    Does anybody know what's wrong here and how to retrieve the 8Bit color-image without stripes?
    Here comes the whole source:
        private BufferedImage resize(int newHeight, int newWidth, BufferedImage image) {
            int iTargetHeight = newHeight;
            int iTargetWidth = newWidth;
            //Create a BufferedImage that fits
            BufferedImage objDownsample = new BufferedImage(iTargetWidth, iTargetHeight, BufferedImage.TYPE_BYTE_INDEXED,(IndexColorModel)image.getColorModel());
            //A map with all necessary rendering hints to optimize the quality of the image
            Map<java.awt.RenderingHints.Key, java.lang.Object> obj_Map = new HashMap<java.awt.RenderingHints.Key, java.lang.Object>();       
            obj_Map.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
            obj_Map.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            obj_Map.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
          // Draw the scaled image
          Graphics2D graphics2D = objDownsample.createGraphics();
            graphics2D.addRenderingHints(obj_Map);
            graphics2D.drawImage(image, 0, 0, iTargetWidth, iTargetHeight, null);
            return objDownsample;
        }Thanks
    Albrecht

    As far as I can tell, this solution only allows compositing within the component that is currently being painted. What would be nice is if I could add a custom composite to say .. a JLabel, which paints based on the colors of the underlying pixel data (ie. from its parent container). In this way you could make a JLabel that always inverts the color of what's underneath.
    Here, painting to the screen using a composite allows me to get the pixels underneath as the destination raster, the pixels in the JLabel as the source raster, and what actually gets painted which is the destination output raster.
    If I paint to a BufferedImage instead, the composite's 'destination raster' is the new BufferedImage's default values which are all black. Thus compositing over this would not have the desired effects described above (inverting the underlying image for instance). The missing piece when rendering to the BufferedImage is first copying the underlying screen data into a BufferedImage before painting to it. How do I do that? Something tells me it's very difficult.

Maybe you are looking for

  • Tperrno set to TPEOS at start of service

    Hi All, I turned TMTRACE on for a laugh and noticed messages of the form.... 085154.FULHAM!appserver.1464.1676.0: gtrid x0 x403a83fc x1:     TRACE:at: } tpalloc = 0x157cf00 [tperrno TPEOS] However, all my tpalloc calls are tested for success and all

  • HELP! my ipod touch has white screen

    My ipod touch 4th gen has all of a sudden stopped working.. it went on the the black screen with the apple icon on it and then it wont turn off. i have tried to restore/restart it but it wont work and i cant get it to switch off untill the battery di

  • Portable Home Directories + Logging into the Server

    I am worried that I may not be able to do what I want to do... I use my server as my work station at home; so I want to be able to log into it as a normal user. I set up my "normal user" as a mobil user so the home directory gets synced with my lapto

  • Differend between JAZN and Dynamic Credentials

    Please dose someone hase an article about this?? I want a clear article where it describes the differend between these two. thank you

  • IPod Touch keeps hitting the home button

    Before I begin, I have a 32GB 3rd generation iPod Touch. I bought it off of Amazon directly and it arrived January 27 of this year. And until 2 days ago, I loved it and it worked great. However, now it keeps hitting the home button on its own. It doe