jcreator - making a matching game - java

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

Related

Java - netbeans - Undo / Redo Code for a notepadGUI

I’m making a notepad app as a Beginner project on NetBeans, in the edit menu, I’m looking To code a Undo Button and also a Redo Button for the last actions performed? For example, if I want to undo a paste or Cut and be able to jump back a few actions to a previous state
For this there are a few possible ways of tackling the problem.
One way, possibly the way I would do it, is store the contents of the notepad after every space key. This would allow you to press the undo button and set the text to the text before the last word was entered. For redo you could save the contents when backspace is pressed and restore it that way.
To implement this I would use an array list which is appended to with the current contents of the notepad (as a String), whenever space is pressed and/or whenever backspace is pressed and use the undo and redo buttons to cycle through the ArrayList.
I can't really give a much more detailed response as I don't know the entirety of your situation.

Check if there's an empty place arround a button

I am making an sliding puzzle game as my college project. The game concept is: you have a 3x3 table but with 8 buttons. When you click a button it have to move itself to an empty place. Is there any way to check if there's an empty place arround my button?
you can put a boolean field in your button class and check it when user requests to move
if you want I can write the exact code.
Good Luck!

JCheckBoxMenuItem stays checked when switching tabs

I have a pretty basic interface of a chromotagram viewer. In the menu I allow the user to reverse the viewer with a JCheckboxMenuItem. Functionally, it does exactly what its supposed to do. My interface allows for multiple chromatograms to be open at once. I will post a few example pictures as I get to my question.
Above I have one tab opened and have yet to reverse the chromatogram.
Above I have clicked the option and it worked.
Here is my issue. If I open another tab and move to it, the option is still checked even though I have yet to click that button. The easy way out would be just to make it a normal button but I just want to know if there is a way that each tabbed could keep track of if its been reversed yet. Would this require multiple instances of the button itself? If anybody has any suggestions, please let me know. Thank you.
if(centralPara.getNumOpen() > 1){
centralPanel = centralList.get(centralPara.getCurrentFrame());
JCheckBoxMenuItem reverseItem = centralPara.getReverseItem();
boolean reversed = centralPanel.getReversed();
reverseItem.setSelected(reversed);
}
in my tab change listener I check to see that we have atleast more than one tab open. if so get the frame we are currently viewing and the top level menu item. Force it be be selected if that the current view frame is selected, or else force it be unselected.

JTable: double-click should keep prior selection

I have a JTable where I can select one or more cells. I also want to react on double-click for doing some extra action for the selected cells. But the problem is, when the user double-clicks, the selection changes to the clicked cell. But I want to keep the prior selection on double-click, so I can handle the double-click for all selected cells.
EDIT:
Related to this question:
Java : ignore single click on double click?
But I hope, there is a better/easier solution for my case.
The problem is, that on the first click the first event goes out. A bit later the second click might come or not. So the first click event does know nothing. As in the proposed solution a timer might do.
What also might do is on the first click to select nothing, but invoke a special selection event a bit later.
SwingUtilities.invokeLater(myRunnable);
and on handling the double click/myRunnable the true selection. Timing might be unavoidable though.
you can use setClickCountToStart() for XxxCellEditor, I don't know something about your JTable

Press buttons without release finger from screen

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.

Categories