Press buttons without release finger from screen - java

I want to press buttons like it shown on this picture http://i.stack.imgur.com/C1NW3.jpg. That is I want to press buttons by holding finger on the screen and moving it along buttons. For example on this pic buttons 1, 2,5,8,9 will be pressed after this procedure.
Sorry for my bad english, but i cant to describe this in a different way.
How I can do this?

Well, sorry for not providing the very simple answer like "use the function xyz()" for this, but I think there are some general ways to do it:
You can create pictures that look like buttons (or bubbles or anything else appropriate), place them in an order that you need and then, getting each coordinate of the pointer (of the finger) on the screen, just check if this pointer gets into some area (maybe rectangle) inside each button. This logical area should be smaller than shown picture to let user move finger not so careful.
Another "solution" would be to put some "jitter" and send "left click" message on each position update along the way. In this case buttons should have some protection from multiple clicks. I remember on stackoverflow.com some advice how to do this: just disable the button on the click event.
Sorry if Android has some solution "out of the box", which I have no idea about, but the described problem seems to be general, not platform-specific.

Related

Java dragging image and dropping on the point

I want to create interactive drag and drop. What I mean is that i have 10 slots and 5 buttons, I want to make that user can drag and drop a button on the slot he wants to. I made it with ComboBox and it works fine but I want to make it more interactive. Is it possible in an easy way or I need a hard code? If so any good help on coding would be appreciated.
//Edit. I made it with ComboBox using setLocation(); with saved every slot position
//Edit again with photo:
You can see several example of Drag and drop in Java here and decide which kind of drag and drop you would like to do:
http://docs.oracle.com/javase/tutorial/uiswing/examples/dnd/

Android-Simulate mouseover/hover

How can you simulate a mouseover event in an android app?
I have to detect if the user is touching/hovering over a particular part of the screen for more than 2 seconds.
you cant hover without a cursor.
but for an ipad there is a simulate hover command for css. unfortently i cant find it, if anyone does find it let me know!
i used it in some code once, im scouring that code for it, im hoping i didnt imagine it.
Case: I wanted a pointer to move a mouse around the screen of my phone via my watch. If somebody finds this in the future:
Pointer image: Tasker allows to create scenes. Create a scene with a canvas as big as you want your pointer to be, add the image you want as pointer as the scene only element, filling the scene.
Coordinates static: Create variables for "X" and "Y" (these are STILL NOT pixels). You want to play around with values on the show scene location applying your variables. 0,0 is top left, 200,200 is bottom right.
Coordinates movement: My approach was having 2 variables "now" and "final" (or other names). So you can tell tasker: Hide scene in Xnow,Ynow; Show scene in Xfinal,Yfinal; Set variables Xnow to Xfinal and Ynow to Yfinal.
With that in mind:
You may want to detect if "mouse overlay image is on top of your desired element.
With a touch screen, users can only touch or not touch, but not hover, so that this part of the question is probably out.
The long touch behavior is implemented inside the various onXXXLongClick() handlers.
How to hover over a link?
I hope this link helps you .
But how can a person hover in a touch device ? Well i have always placed my fingers .
Try adding onClick="return true" in your link a href tag
About us
the onClick="return true" should simulate a cursor hovering over then leaving the hover area. effectivly giving you a hover effect.
keep in mind, ur finger has to touch the button for the hover effect to take place, which means the user will only see the change for a second or two before the link loads a page.

How to completely remove a button's background instead of just hiding it

I'm trying to create this game
in Java for my school A-level course. I'm currently trying to use an individual button for each of the squares and cannot in any way remove the buttons's background. I've tried setBackground(false) which hides the background, but it is still there so still clickable, which you can imagine completely screws up the board.
Ultimately what I'm asking is how to make a button from a picture the same size as the picture, without any extra backgrounds at all, not just hidden.
Here is a picture of what I mean:
Any help/suggestions would really be appreciated, I'm desperate!
There was a question on here for creating custom buttons with java:
Creating a custom button in Java
The answer to this question might solve your problem.

Swing - Changing the content of a panel using UpdateUI

I am going through a legacy application which is using Swing and i am struggling to figure out how the screens are changing when a user clicks a button. One of the reasons i cant figure this out is because this is the first time i am using Swing. I have read a book and got the basics but still struggling.
Basically, the screen i am looking at has a JSplitPane which has a number of shortcut buttons on the left and an empty pane on the right. When i click on the button, the right side pane is populated with a different screen depending on the button pressed.
Going through the code, i was expecting somewhere that there will be something that calls a setVisible() method depending on which button is pressed.
The actionPerformed method for each of the shortcut buttons looks something like this:
void shortCutBtn_actionPerformed(ActionEvent e) {
propertyChangeListeners.firePropertyChange("selectedShortCut", previousShortCutSel, currentShortCutSel);
mainPanel.updateUI();
}
I have gone through most of the code and came to a conclusion that the above code is what is causing the frame switching but i dont understand how that is happening.
Each screen is identified by a numeric constant. In the above code example, previousShortCutSel and previousShortCutSel refer to a numeric value that represents individual screens screen.
I have tried to look for documentation of how updateUI() works but i am lost. How does the above cause the content of the right panel of the JSplitPanel to be updated with a new screen?
This is not an appropriate use of updateUI(), which "Resets the UI property to a value from the current look and feel." As the example itself may be unreliable, consider studying another. GoogleOlympiad, for example, sets a label's icon using a (cached) image.
ImageIcon image = getImage(index);
imageLabel.setIcon(image);
(source: drjohnbmatthews at sites.google.com)
As per comments by ziggy (glad it helped)
Have a look at the PropertyChangeListeners that appear to be added in the code. In particular the propertyChange(PropertyChangeEvent e) method is where the code which changes the content will be present.
+1 to trashgod nice example/advice as always

Java - Creating an RPG dialog

So this may seem strange, but I am trying to create a very basic game that works somewhat like what an older RPG game may have as the interface (think choosing attacks from a list (ex: Pokemon)).
Right now I have a class that extends JFrame, and it contains private variables of three panels: one for displaying the sprites at the top 75% of the screen, and the other two are the ones I wish to display text on (one for announcements like, "CRITICAL HIT" and the other for the selectable choices). The second of the text boxes would only be visible sometimes, but that is irrelevant.
Can anybody start me off or lend me a hand? I am finding many way but none that seem to work for my needs.
Edit: My game is laid out and the sprite panel works exactly as it should, as much as it may sound like it, I am not rushing into anything blindly. I have the game working except for displaying the dialogs in an effective way.
EDIT 2: Ok maybe I am being unclear, my basic concern is finding the best Java component to draw strings to the bottom panels. The strings will be changing regularly, so some methods that I have tried such as the Graphics drawString() are not very effective.
Thank you,
roflha
Well, your original question statement lacks any actual cohesive question, other than "Can anybody start me off or lend me a hand?" which makes it rather hard to figure out what you really need. I discerned that what you want help from us about is displaying dialogues that popup to the user when some event happens. If you don't care too much about special effects, there are three easy ways to do this:
1) Simply have sprites for your messages, and set them to visible as needed. If you have a limited number of important messages, this makes it easy to control the visibility/flashiness of the message.
2) JTextArea allows you to simply print some text to a box. It is useful if you have a wordy console or messages that can't simply be a few images. You would just have a JTextArea in your panel, and update it as needed:
JTextArea messageBox;
messagePanel.add(messageBox);
//displays a message
messageBox.setText("CRITICAL HIT!!!");
But the user may not notice when the text changes, since it changes instantly. Whether you want to flash the text, or display some animation on top of the text area is up to you.
3) If you want a more intrusive message, you can actually have a popup dialogue where the user would have to click "OK" to continue. This is relatively easy to do, and you can even put custom icons for the message:
http://download.oracle.com/javase/tutorial/uiswing/components/dialog.html
JOptionPane.showMessageDialog(myFrame,
"You got a critical hit!!!",
"Critical Hit",
JOptionPane.INFORMATION_MESSAGE,
criticalHitIcon);

Categories