Results 1 to 18 of 18
- 02-15-2009, 08:44 AM #1
Member
- Join Date
- Feb 2009
- Posts
- 8
- Rep Power
- 0
[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:
Already thanks,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. } } }
Perfectworld
- 02-15-2009, 08:59 AM #2
Member
- Join Date
- Feb 2009
- Posts
- 48
- Rep Power
- 0
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)
- 02-15-2009, 09:02 AM #3
Member
- Join Date
- Feb 2009
- Posts
- 8
- Rep Power
- 0
Yes, but my question is how would I change that?
- 02-15-2009, 09:06 AM #4
Member
- Join Date
- Feb 2009
- Posts
- 48
- Rep Power
- 0
w = getx();
h =gety();
repaint();
and make w and h the cords for the image.
- 02-15-2009, 09:12 AM #5
Member
- Join Date
- Feb 2009
- Posts
- 48
- Rep Power
- 0
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.
- 02-15-2009, 09:15 AM #6
Member
- Join Date
- Feb 2009
- Posts
- 8
- Rep Power
- 0
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
- 02-15-2009, 09:17 AM #7
Member
- Join Date
- Feb 2009
- Posts
- 48
- Rep Power
- 0
you have an aim? i dont use MSN any more.
i have a myspace and a facbook also.
- 02-15-2009, 09:20 AM #8
Member
- Join Date
- Feb 2009
- Posts
- 8
- Rep Power
- 0
I don't have aim, otherwise connect to IRC? We can meet up there, or if you have mail I'll send it.
- 02-15-2009, 09:20 AM #9
Member
- Join Date
- Feb 2009
- Posts
- 48
- Rep Power
- 0
just toss the pictures on the tinypic.com and put the links here
- 02-15-2009, 09:22 AM #10
Member
- Join Date
- Feb 2009
- Posts
- 8
- Rep Power
- 0
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.
- 02-15-2009, 09:30 AM #11
Member
- Join Date
- Feb 2009
- Posts
- 48
- Rep Power
- 0
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
- 02-15-2009, 09:33 AM #12
Member
- Join Date
- Feb 2009
- Posts
- 8
- Rep Power
- 0
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.
- 02-15-2009, 09:43 AM #13
Member
- Join Date
- Feb 2009
- Posts
- 48
- Rep Power
- 0
lol.. are you doing this to show off to your friends saying you have that item lol?
- 02-15-2009, 09:46 AM #14
Member
- Join Date
- Feb 2009
- Posts
- 8
- Rep Power
- 0
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.
- 02-15-2009, 09:57 AM #15
Member
- Join Date
- Feb 2009
- Posts
- 48
- Rep Power
- 0
i know.. its runescape. i use to play. lvl 76 ; ]
- 02-21-2009, 03:34 AM #16
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.
- 03-02-2009, 05:37 PM #17
Member
- Join Date
- Feb 2009
- Posts
- 8
- Rep Power
- 0
I was looking around abit, couldn't find anything good. Only I could think of was something like this;
And for the performed, I didn't come farther then this;Java Code:Icon icon = new ImageIcon("image"); JButton button = new JButton(icon);
Java Code:public void actionPerformed(ActionEvent ae) {
- 01-16-2010, 08:09 AM #18
Member
- Join Date
- Jan 2010
- Posts
- 1
- Rep Power
- 0
Similar Threads
-
Double clicking executables jar files?
By cruxblack in forum New To JavaReplies: 6Last Post: 04-23-2009, 02:00 AM -
Changing images by clicking arrow buttons. help?
By ashton in forum New To JavaReplies: 3Last Post: 02-08-2009, 11:29 AM -
Moving textboxes
By GabWit in forum New To JavaReplies: 2Last Post: 01-26-2009, 04:07 PM -
Java3D: Clicking and getting coordinates?
By seabhcan in forum Advanced JavaReplies: 0Last Post: 01-11-2008, 02:46 PM -
moving a file
By Java Tip in forum Java TipReplies: 0Last Post: 11-10-2007, 07:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks