Adding a picture over a picture

Get help on programming - C++, Java, Delphi, etc.
Post Reply
Worship
Registered User
Posts: 505
Joined: 28 Jan 2006, 02:00
Location: Johannesburg

Adding a picture over a picture

Post by Worship »

Hi

I doing this school project and now it seems i require putting a counter (like a token) on a board game. Obviously this token has to move position. So could someone please enlighten me on how i can do this and how i can move this token around. Like if there is a method to set position of the token

Thanks
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Post by rustypup »

isn't this the same question you asked over here ?

the answer remains "yes", although you will need to get your threading right in order to prevent anomalies or flickering.....
Most people would sooner die than think; in fact, they do so - Bertrand Russel
Worship
Registered User
Posts: 505
Joined: 28 Jan 2006, 02:00
Location: Johannesburg

Post by Worship »

Okay i understand everything an i created a gif token and everything but my problem is i don't know how to use the setPosition method could you help me? I tried token.setPosition[300,300] but it says no method found in ImageIcon...
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Post by rustypup »

your paint op is a relative postion within a component... you would typically override the component's paint method..

Code: Select all

public void paint(Graphics g){
    super.paint(g);
    Graphics2D g2d = (Graphics2D)g.create();//cast to 2D instance
   //some code to update the b.ground
   //some code to set context's scale
   //force AA on.... some impact on speed...
   g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   //the observer is normally 'this'...
   g2d.drawImage(someImage, someXoffset, someYoffset, someObserver);
   g2d.dispose();
}
this method is called on every re-paint....

you would need to extract the gif frames in order to have them rendered correctly, as awt painting cannot be processed on ImageIcon instances, (which is more of an image management tool than anything else...) if you're hoping to use the gif as natively as possible, your board will have to be made up of a number of labels, which can then have their ImageIcon property set/unset to simulate movement... not very practical and it looks horrible....

Consider using the ImageIO class, and it's ancilliary plugins, for image operations....

Code: Select all

ImageInputStream iis = ImageIO.createImageInputStream(new File("someFile"));
Iterator<ImageReader> rdrs = ImageIO.getImageReaders(iis);
int tally = 0;
BufferedImage[] frames = null;
while(rdrs.hasNext()){
     try{
            ImageReader rdr = rdrs.next();
            rdr.setInput(iis);
            tally = rdr.getNumImages(true);
            frames = new BufferedImage[tally];
            for(int i = 0;i<tally;i++)
                frames[i]=rdr.read(i);
            break;//ignore remaining readers..
      }
      catch(Exception e){
            e.printStackTrace();
      }
}
>>ImageIO specs

the above example is very much what ImageIcon does, only, once done, you have no reference to the individual frames, and have to introduce additional complexity just to get at its contained image... the ImageIO approach resolves that. while at the same time being sufficiently generic enough not to care which input format is being used, (png for high-def, gif/jpg for the others... even tiff)...
Most people would sooner die than think; in fact, they do so - Bertrand Russel
Post Reply