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
Adding a picture over a picture
- rustypup
- Registered User
- Posts: 8872
- Joined: 13 Dec 2004, 02:00
- Location: nullus pixius demonica
- Contact:
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.....
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
- rustypup
- Registered User
- Posts: 8872
- Joined: 13 Dec 2004, 02:00
- Location: nullus pixius demonica
- Contact:
your paint op is a relative postion within a component... you would typically override the component's paint method..
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....
>>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)...
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();
}
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();
}
}
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