I'm new to stackoverflow. I have this question for Java, though, and there might be a simple way to do it but I don't know how.
Here is my problem. I have my game, on the press of a button (X), to display text on the screen under the title of the top left of the game. That works fine, but lets say I have multiple. If I press N which could be the fifth one, it puts it what looks like random on the screen. But if I have all the buttons pressed, it will look normal, because all will be in line with each other.
Here is the code I have to write a line under the title of the game.
var8.drawStringWithShadow("Test", 2, 11, 0xFFFF);
The first parameter is the text, second is x, 3rd is y.
Now, I have it drawing another one at the press of another key.
var8.drawStringWithShadow("Test2", 2, 20, 0x008B);
As you can see, the y parameter was incremented by 9, so it would be under the other one.
What I want to do, is have the Y always be the same (11), But, if text is already there, push it down.
So lets say I had "Test" being displayed. But then I press the button to enable "Test2", and I want it to take the place of "Test", but not overrite it, when it is pressed, if "Test", or any other buttons are enabled, it will increment the y of "Test" or another one by 9.
I hope there is a simple way to do this, if there is, please tell me. Thanks!
Make a counter for how many strings are there and let
y = counter*9 + 11
Related
I am programming a lottery program in JavaFX (6 numbers of a 6x7 field + 1 lucky number) which allows the user to create max 10 tips at once. Then the program evaluates if he won.
My current problem is to delete a Tip that has been added. I have a Class "Tip" which consists of an HBox with 7 labels inside (for the 7 chosen numbers) and a button to delete this Tip (so every Tip has its own delete button).
My function to add a Tip works (even though, I don't really know if this is really clean. So if you see any improvements, I'd be really thankful! :-)).
Under the following link, you can find my entire code:
https://github.com/Lucindor/Lottery.git
The main issue or part that I'm stuck is in the Controller from line 73 to 80 (deleteTip method).
My main idea was to removethe parent of the button (which should be the Tip(?)), which should have removed the entire tip...but this didn't work. I couldn't get any ideas more.
In the end, I want to be able to click on any delete button which removes this tip and moves all the tips below (So that it's like a list).
Thanks a lot!
I'm doing a Matching/Memory Game in JCreator using buttons and if-else statements
When you click the buttons, the image clicked will pop up then if you click the next one, but it's not the same image, then both will close. If you get the correct matching image, they both disable. My problem is the logic of matching it.
What will I do or use to make my program know that two buttons match?
You need to add an ActionListener. Use that link to find out how to detect whether buttons are being pushed and what to do when pushed. To make an image appear, use an icon with the button. When you click, a number changes to a value. If you click another and a number is the same value, then they become disabled. If they are diffrent, then the icon is changed and the number reverts to zero. To disable, use button.setEnable(false);
Use this link for help with button icons/general button help.
Another thing you can do, although it takes more time, is giving each button a numeric value and use RandNum to decide them. If you set it as a constant variable then you can use that to match them
I wanted to make a "memories" or "find pairs" game for Java, just to start with a basic game before starting something more difficult. My game works very well, but I just have 1 big problem. I don't really know how to hide the 2 images x seconds after the user clicks on the second one.
This is what is done:
The game is created with 4x4 buttons in a array
The values of the cards are distributed (name, position, icon)
The user then clicks on the first card, which shows up immediately
The user clicks on the second one, if the first is equal to the second one then disable the 2, if not then re-hide the 2.
But I don't know how I can make the program show the second card and then after x seconds hide the 2...
How can I solve this?
Depending on what framework you are using, there should be a timer utility available to you.
For instance, if you are using Swing, then you should be able to use javax.swing.Timer as suggested in the above comments. Follow this link for a simple Swing Timer tutorial. As they say on that page, swing timers can be used in one of two ways and one of those ways is:
To perform a task once, after a delay
This sounds like exactly what you are trying to achieve.
You could also try a library like Joda Time which has lots of features and options.
you should make match function and another unmatch function and inside the unmatch function
you can use setTimeout and give the two cards class(flip) when you choose them and after certain time and when they didn't match remove this flip class.
I am creating a 15 puzzle game in java. I have already created a game panel and written method that finds the position of the empty place (not JButton) on a field and a method that controls whether it is a winning combitanion or not (JButtons on a correct places). So, I got something like this:
I have a trouble with writing an ActionListener. Is it possible to write a method that determines that actionListener should be added to the JButtons that surround the empty space.
I really need some tips or/maybe already written methods/solutions.
Thanks!
I think your best bet would be to keep the action listener active on all the buttons. When clicked, it simply does nothing if it determines itself to not be adjacent to the empty box.
I would recommend ditching the idea of only adding actionListeners to the buttons that surround the empty space: keep actionListeners added to all buttons and only process a click if it is valid.
Also, in my experience, it is very user-hostile to only allow a click on one of the tiles that surround the empty space. In the example picture, you are planning to only allow a click on 7, 1, and 11. You should allow a click on 5, 7, 1, 13, 14 and 11. So, for example a click on 14 should move 1, 13 and 14 to the left.
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.