Results 1 to 3 of 3
  1. #1
    ofir3dvb is offline Member
    Join Date
    Mar 2008
    Posts
    3
    Rep Power
    0

    Default 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.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    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);
        }
    }

  3. #3
    ofir3dvb is offline Member
    Join Date
    Mar 2008
    Posts
    3
    Rep Power
    0

    Default

    thank you !

    i think that will be it, i just didnt know who to implement it :)

    thanks again i will check it out !

Similar Threads

  1. Image Verification
    By peiceonly in forum Java Servlet
    Replies: 2
    Last Post: 04-04-2009, 07:38 AM
  2. JWindow/JFrame with boarders
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-12-2008, 11:35 AM
  3. Replies: 0
    Last Post: 01-08-2008, 05:29 PM
  4. Image resizing
    By alley in forum Java 2D
    Replies: 2
    Last Post: 11-13-2007, 10:10 AM
  5. How to mouse-drag a JWindow?
    By cruxblack in forum New To Java
    Replies: 3
    Last Post: 08-06-2007, 09:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •