Results 1 to 3 of 3
Thread: Image with JWindow -> trails
- 03-16-2008, 04:18 PM #1
Member
- Join Date
- Mar 2008
- Posts
- 3
- Rep Power
- 0
Image with JWindow -> trails
Hi all !
First let me apologize for my bad english.
Secondly, I tried to show on the screen transpaernt animated gif, in another words, sprite(character) which walk on the desktop, well, i succsed, but there is a problem, if the sprite move is head, then on the screen you will see the sprite before and after the movmenet, there are trails.
for those who not understand the problem:
my code very simple at this moment:
public class WS extends JWindow
{
Image img=null;
Image img2=null;
Toolkit tk=null;
public WS()
{
tk=Toolkit.getDefaultToolkit();
this.setSize(500, 500);
this.setLocation(500, 500);
img2=tk.getImage("MijalNo.gif");
this.prepareImage(img2, null);
this.setVisible(true);
}
public void paint(Graphics g)
{
g.drawImage(img2, 0, 0, this);
}
}
i hope that you could help me.
thank you.Last edited by ofir3dvb; 03-16-2008 at 04:21 PM.
- 03-17-2008, 01:18 AM #2
Java Code:import java.awt.*; import java.awt.image.BufferedImage; import java.io.*; import javax.imageio.ImageIO; import javax.swing.*; public class WS extends JPanel { BufferedImage img = null; Dimension size = new Dimension(100,100); public WS() { try { String path = "MijalNo.gif"; img = ImageIO.read(new File(path)); } catch(IOException e) { System.out.println("Read error: " + e.getMessage()); } size.setSize(img.getWidth(), img.getHeight()); } protected void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage(img, 0, 0, this); } public Dimension getPreferredSize() { return size; } public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new JScrollPane(new WS())); f.setSize(500, 500); f.setLocation(200, 100); f.setVisible(true); } }
- 03-18-2008, 05:21 PM #3
Member
- Join Date
- Mar 2008
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
Image Verification
By peiceonly in forum Java ServletReplies: 2Last Post: 04-04-2009, 07:38 AM -
JWindow/JFrame with boarders
By Java Tip in forum Java TipReplies: 0Last Post: 03-12-2008, 11:35 AM -
Converting multiple banded image into single banded image... Image enhancement
By archanajathan in forum Advanced JavaReplies: 0Last Post: 01-08-2008, 05:29 PM -
Image resizing
By alley in forum Java 2DReplies: 2Last Post: 11-13-2007, 10:10 AM -
How to mouse-drag a JWindow?
By cruxblack in forum New To JavaReplies: 3Last Post: 08-06-2007, 09:52 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks