Results 1 to 7 of 7
Thread: Basic Image Questions
- 11-21-2009, 10:42 PM #1
Member
- Join Date
- Nov 2009
- Posts
- 4
- Rep Power
- 0
Basic Image Questions
Hello, I want to be more informed on the basic syntax for my problem.
In our Java class we are making games that basically only requires sound and animation. For my game I wanted to do that "adding game" which is a two player game involving your hands. I am currently trying to just do a detailed psuedo-code for my game.
So my questions are:
1. How would I set up a panel with images into specific places? (In my game I need 4 hands so I want two sets of hands on the bottom of the panel, and another set on the top)
2. How would you know if the mouse clicked within a certain image's boundary and know which image that is? (In my game I need to know the sequence a user clicked on the hand images to determine what game function should be executed. For example: If I clicked on player one's right hand and then player two's left hand an animation would occur)
If my questions are too general please feel free to ask for specifications. Thank you, to anyone who answers my post!
-
Swing? AWT?
Either use layout managers or absolute positioning (the null layout manager). We in general prefer to use layout managers since that lets the managers handle the dirty work for us, but when this is impossible, fall back on null layouts. Just realize that if you use a null layout, you are responsible for both the location and size of each component held by that container.1. How would I set up a panel with images into specific places? (In my game I need 4 hands so I want two sets of hands on the bottom of the panel, and another set on the top)
If Swing, then I imagine each image will be held in its own JPanel or JLabel. You could give these components a MouseListener and listen for mousePressed events.How would you know if the mouse clicked within a certain image's boundary and know which image that is? (In my game I need to know the sequence a user clicked on the hand images to determine what game function should be executed. For example: If I clicked on player one's right hand and then player two's left hand an animation would occur)
- 11-21-2009, 11:21 PM #3
Member
- Join Date
- Nov 2009
- Posts
- 4
- Rep Power
- 0
Sorry, I'm not too sure what you mean by "Swing?" or "AWT?". I thought those are just different tools to writing a program. And I assume I'm probably going to be using both in my game.
Making each image into a panel/label sounds like a great idea, that helped make things a little clearer for me.
Also in regards to the mouseListener class , instead of having to keep track of the numerical coordinate point the user clicked, is there a way I can get the event in terms of which panel it clicked? (Like with a radio button listener, we determine the action event in terms of the name we gave to the button. Can we do this for panels and mouseClicked events?)
-
Swing and AWT are both toolkits used for building GUI applications. AWT is the older of the two while Swing which was built on top of AWT is the more recent, the more powerful and in general the more popular. You will usually create a GUI using graphical components from one or the other toolkits but not from both, and I suggest that you choose Swing.Sorry, I'm not too sure what you mean by "Swing?" or "AWT?". I thought those are just different tools to writing a program. And I assume I'm probably going to be using both in my game.
If you add a MouseListener to a JPanel that has an image for instance, that JPanel will "know" when it is being clicked since its mouse listener will only be activated if this in fact happens. In this situation, there's no need to keep track of numerical coordinates.Also in regards to the mouseListener class , instead of having to keep track of the numerical coordinate point the user clicked, is there a way I can get the event in terms of which panel it clicked? (Like with a radio button listener, we determine the action event in terms of the name we gave to the button. Can we do this for panels and mouseClicked events?)
- 11-21-2009, 11:52 PM #5
Member
- Join Date
- Nov 2009
- Posts
- 4
- Rep Power
- 0
Ah, I see, well thank you for the information. Alright that's good to hear I won't be needing to keep track of the coordinates.
I think I might be a bit confused on the process, as I am unsure of how I read in a mouse event for a clicked panel. Do I use the getSource() method and compare the source with the titles of the panels? Also, how would I know if a certain sequence is being clicked by the user? As mentioned before my game needs two clicks by the user over two different image panels to execute any actions.
-
getSource will in fact tell you which component has been clicked. As for your program logic, for that you'll need to have a counter in your MouseListener, and you'll want to add the same MouseListener to all the components that need it.
- 11-22-2009, 12:20 AM #7
Member
- Join Date
- Nov 2009
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
Problems drawing a section of an image onto another image.
By Cain in forum Java 2DReplies: 1Last Post: 04-17-2009, 12:44 AM -
[SOLVED] manipulating the pixel values of an image and constructinf a new image from
By sruthi_2009 in forum AWT / SwingReplies: 14Last Post: 04-10-2009, 08:46 AM -
Need some really basic help
By Mayur in forum New To JavaReplies: 6Last Post: 01-24-2009, 06:00 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 -
help with basic example
By fred in forum New To JavaReplies: 1Last Post: 07-20-2007, 05:45 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks