Move image with mouse cursor in Java applet [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I've been trying to teach myself Java recently and as part of the process I'm working on a Calorie Calculator applet.
Just to make things more fun I was thinking to use the picture of a smartphone as the background image.
What I want to know is: say I also had a picture of a stylus pen; any way I could make that move with the mouse once I've clicked on it? Preferably this image would replace the mouse cursor (though not mandatory). It should stick to the mouse cursor until the applet is closed, regardless of any other events occurring (clicking other images, buttons, text areas etc.)
I appreciate your assistance!

..any way I could make that move with the mouse once I've clicked on it?
The main component needs a MouseListener. See How to Write a Mouse Listener for details.
Preferably this image would replace the mouse cursor (though not mandatory).
Look to the Cursor API for that.
This sounds like a classic XY problem.
What you might actually be looking for is Drag and Drop and Data Transfer.

Related

How can I create a clickable grid in java? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm creating Conway's game of life in java, and I want to make a clickable on screen grid to toggle the cells on/off before pressing start. What is the best way to do this? A grid of JButtons won't do it for me as it looks horrible (unless theres a way of changing how they look?)
any help is greatly appreciated - thanks!
I would use raw graphics 2D draw commands to manually draw rectangles in AWT for Conway's Game of Life. You can still listen to click events for the frame and then use the x and y coordinates to calculate the cell. It will be a lot faster than using UI components, as well.

Enlarge clickable area of button [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a Java applet which is running on a touchscreen monitor. I want to activate e.g. a button's action even when the user didn't hit it exactly. Maybe in a range of 5 pixel of the click, the nearest clickable object have to trigger his action.
How do I enlarge a button's hit area?
For example, if the size of a button is (width=100, height=25), the clickable area of this button should be a little bit larger than the button itself (width=120, height=45)
What I´m looking for is like TouchDelegate class from Android...
...Helper class to handle situations where you want a view to have a larger touch area than its actual view bounds...
There is padding option for this purpose.
So if you use padding your button looks smaller than the actual clickable area.
Sorry I don't know how to set it in Java applet. Try this post, I suppose Insets correspond to padding OR try this (like stated here):
button.setMargin(new Insets(10,10,10,10));
Edit
If you can use drawable resource to serve in place of a button there is another way - just make border transparent.

Animated drag and drop in JTable [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Do you know some way to make drag and drop in table more user-friendly? For example: row stick to mouse on drag, and other rows swap places when dragging. Can you recommend me some library for this ?
I'd suggest you take a little time to have a read through The Rabbit Hole which has some excellent articles on the topic of drag'n'drop.
These are most of the articles of interest
Smooth JList Drop Target Animation
Smooth Tree Drop Animation
My Drag Image is Better than Yours
Dead Simple Drags
Fancy Drops
Drag Images for Everyone
Drop Target Navigation, or you drag your bags, let the doorman get the door
Swing Drag Images (Improved)
Well, Java libraries are usually not good really at the "animation" thing. There is a way to do this using the D and D libraries Java comes with but it would require swapping the values of the rows, rather than swapping the rows themselves.
Java is very limited at this kind of stuff. Either you hard code your own library, or use some other language that has libraries for tasks like these.

Swing drag and drop [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I would like to implement a game board in swing (needs to be a table, though about either jtable or gridlayout etc ...) where I will be able to drag and drop a picture on to this game board and all the cells that the picture fell on will get a notification that they were chosen.
Can anyone help with that? how do I get a couple of cells in a table know that an object was dropped on them?
Have a look at this tutorial.
I think you have to spent some time with Google. I found the following with a little time with Google.
Introduction to DnD
How to drag and drop with Java 2, Part 1
How to drag and drop with Java 2, Part 2
Drag and Drop Effects
Hope this helps :)
Read this and if you have an more specific questions come back and ask them.

How do I create a "jumping" circle in Java GUI? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I would like to have a red filled circle at some place in my window. After the click on the circle, the circle should jump from the original place to a new one (disappear from the old place and appear on the new one). What would be the best way to do it?
I also would like to know how to draw a filled circle in Java. Are there any simple tools to do it? Or may be the easiest way is to use an image created by some other software?
ADDED:
For the beginning I would like to have just a redraw (a circle disappear and at "the same moment" it appears on the new position). I think it will be simple that some visual effects and I would like to start from the simples possible choice.
This can be done using Swing, Graphics2D and a custom JPanel. The tutorial contains a similar example:
http://java.sun.com/docs/books/tutorial/uiswing/painting/step3.html

Categories