Results 1 to 18 of 18
  1. #1
    Perfectworld is offline Member
    Join Date
    Feb 2009
    Posts
    8
    Rep Power
    0

    Default [Applet] Clicking images & moving them.

    Hello java-forums,

    This is my first time being here. I am having a problem with images on applets. I loaded an image as a background, and one image above it (The seed dibber). My main problem is that I only can click on 10 X and 10 Y, however the picture is loaded on much more coordinates.

    I'd like to show you mine applet, but I can't since I am under the 20 postcount. If you need the picture add william@williaminc.nl on MSN.

    Any way, I can give you the code:

    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    
    
    public class ImageTest extends Applet implements MouseListener {
    
       private Image img;
    private Image img2;
    
       public void init()
       {
          img = null;
    addMouseListener(this);
       }
       public void loadImage()
       {
          try
          { 
             img = getImage(getDocumentBase(), "Inventory.png");
    img2 = getImage(getDocumentBase(), "Lol.png");
          }
          catch(Exception e) { }
       }
       public void paint(Graphics g)
       {
          if (img == null)
             loadImage();
          g.drawImage(img, 0, 0, this);
    g.drawImage(img2, 10, 10, this);
       }
    
    
    public void mouseClicked(MouseEvent e) { }
    public void mouseEntered(MouseEvent e) { }
    public void mouseExited(MouseEvent e) { }
    public void mouseReleased(MouseEvent e) { }
    
    public void mousePressed(MouseEvent e) {
    if (e.getX() == 10 && e.getY() == 10) {		
    //All the removign & Drawing stuff.
    	}
    }
    }
    Already thanks,

    Perfectworld

  2. #2
    ramsrocker is offline Member
    Join Date
    Feb 2009
    Posts
    48
    Rep Power
    0

    Default

    theres a few things wrong i see.

    theres no {} in the if statement in your paint. and the reason you can only click on 10x, 10y is

    if (e.getX() == 10 && e.getY() == 10)

  3. #3
    Perfectworld is offline Member
    Join Date
    Feb 2009
    Posts
    8
    Rep Power
    0

    Default

    Yes, but my question is how would I change that?

  4. #4
    ramsrocker is offline Member
    Join Date
    Feb 2009
    Posts
    48
    Rep Power
    0

    Default

    w = getx();
    h =gety();
    repaint();


    and make w and h the cords for the image.

  5. #5
    ramsrocker is offline Member
    Join Date
    Feb 2009
    Posts
    48
    Rep Power
    0

    Default

    god that code actually compiles wtf... it goes against every good programming rule!!

    idk man.. i might be able to help more if i could see the image. im not sure.

  6. #6
    Perfectworld is offline Member
    Join Date
    Feb 2009
    Posts
    8
    Rep Power
    0

    Default

    You can add me on MSN, or I could mail you the picture if you want. And yes, it compiled fine.

    I either can't post my MSN here :X

  7. #7
    ramsrocker is offline Member
    Join Date
    Feb 2009
    Posts
    48
    Rep Power
    0

    Default

    you have an aim? i dont use MSN any more.

    i have a myspace and a facbook also.

  8. #8
    Perfectworld is offline Member
    Join Date
    Feb 2009
    Posts
    8
    Rep Power
    0

    Default

    I don't have aim, otherwise connect to IRC? We can meet up there, or if you have mail I'll send it.

  9. #9
    ramsrocker is offline Member
    Join Date
    Feb 2009
    Posts
    48
    Rep Power
    0

    Default

    just toss the pictures on the tinypic.com and put the links here

  10. #10
    Perfectworld is offline Member
    Join Date
    Feb 2009
    Posts
    8
    Rep Power
    0

    Default

    I did, but I can't do it with a normal way.

    i39.tinypic.com/2cs98w2.jpg

    That with http before and you got it.

  11. #11
    ramsrocker is offline Member
    Join Date
    Feb 2009
    Posts
    48
    Rep Power
    0

    Default

    ahhahaa runescape...

    alright man.. idk what to say. check back tommorow when some more advanced programmers are on. im sure theyll be able to help you ALOT more then i can

  12. #12
    Perfectworld is offline Member
    Join Date
    Feb 2009
    Posts
    8
    Rep Power
    0

    Default

    It's more testing, I am trying to make something that when you click it goes in inventory spot :p. So, yes, guess I'll wait.

  13. #13
    ramsrocker is offline Member
    Join Date
    Feb 2009
    Posts
    48
    Rep Power
    0

    Default

    lol.. are you doing this to show off to your friends saying you have that item lol?

  14. #14
    Perfectworld is offline Member
    Join Date
    Feb 2009
    Posts
    8
    Rep Power
    0

    Default

    No, I just want to make an applet that you click on a item that it goes into inventory. I might start doing something later with a game so.

  15. #15
    ramsrocker is offline Member
    Join Date
    Feb 2009
    Posts
    48
    Rep Power
    0

    Default

    i know.. its runescape. i use to play. lvl 76 ; ]

  16. #16
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    ok, the easiest way to do this is probably to use Swing components as your inventory items and other interface bits. For example, the seed dibber would extend JPanel or somesuch. Add a mouse listener to the containing window and you can use the getComponentAt() method with the co-ordinates from the MouseEvent. Then you'll know when you click and what you've clicked on.

  17. #17
    Perfectworld is offline Member
    Join Date
    Feb 2009
    Posts
    8
    Rep Power
    0

    Default

    I was looking around abit, couldn't find anything good. Only I could think of was something like this;

    Java Code:
    Icon icon = new ImageIcon("image");
        JButton button = new JButton(icon);
    And for the performed, I didn't come farther then this;

    Java Code:
      public void actionPerformed(ActionEvent ae) {

  18. #18
    befast is offline Member
    Join Date
    Jan 2010
    Posts
    1
    Rep Power
    0

    Default

    i have wanting to divide image using mouse with out cover the other image or crossing it how can i use it is the same as image puzzle?

Similar Threads

  1. Double clicking executables jar files?
    By cruxblack in forum New To Java
    Replies: 6
    Last Post: 04-23-2009, 02:00 AM
  2. Changing images by clicking arrow buttons. help?
    By ashton in forum New To Java
    Replies: 3
    Last Post: 02-08-2009, 11:29 AM
  3. Moving textboxes
    By GabWit in forum New To Java
    Replies: 2
    Last Post: 01-26-2009, 04:07 PM
  4. Java3D: Clicking and getting coordinates?
    By seabhcan in forum Advanced Java
    Replies: 0
    Last Post: 01-11-2008, 02:46 PM
  5. moving a file
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-10-2007, 07:52 PM

Posting Permissions

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