Java - netbeans - Undo / Redo Code for a notepadGUI - java

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.

Related

Dual-input for 2 TextFields in JavaFX on one machine

I am working on a project in Java using JavaFX. The project is for a Cafe notification system that has a front end for the customers and has a front end for the cooks and I am running a dual display where one display has the user front end and another display for the cooks front end. The problem is that if there are 2 keyboards connected to the raspberry pi, both input will be in the same TextField because you can't select more than one TextField on a single machine.
What I think could work is that the keyboard for cooks is just the number pad and the users have a normal keyboard without a numberpad. So if there was a way to grab input from the numberpad (since they have different key codes then the numbers on the top of a keyboard) and enter text into the cook TextField without the window being in focus, that would solve my issue I just don't know how to go about that. The user input would just be entered normally since it will be focused on the user UI and they can click for different text fields.
Is that method possible? Is there a better method? Or is this whole thing not feasible and I should just switch to 2 separate raspberry pi's? (please see if it is possible before going straight to 2 devices)
For reference the github project is here: https://github.com/thatoneguy43/CafeBuzzerSystem
I'm hoping I didn't leave any important information out, this is my first post here. If you need any more info from me or have any questions ask away.

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.

Undo button for Image editor

I have a program that load images and let user edit images with options that I provided.
I'm working on the Undo/Redo button. So when I click on the Undo button, it should bring my image back to the last time before editing. I have ideas about UndoManager but I'm really don't know how to create a function for that.
Should I cast my image to BufferedImage?
I recommend looking into Command pattern. If you are using Swing, that means Actions.
If you do it right, you can have "unlimited" undo/redo easily. You might need to serialize your edits after some time, to avoid running out of memory.

jcreator - making a matching game

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

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

Categories