How to delete a Tip in a lottery program with a button? - java

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!

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.

Nesting a button group within a button group in android?

i am fairly experienced at coding in java but i am just learning to build graphical user interfaces in android environment. I have searched alot for the answer to this question but i wonder if im not searching for the right thing?
I want to be able to choose between 2 radio buttons, and if the first of these radio buttons is chosen then a group of 2 more radio buttons should be chosen from. Its hard to explain exactly what i mean so i hope this helps.....
Choice One
1.a choice one a
1.b choice one b
Choice Two
So, if 'choice one' is picked then the user MUST pick from choices 1a OR 1b, whereas if the user picks 'choice two' then the sub options (1a and 1b) are not even available (greyed out i suppose).
I thought i could just nest one RadioGroup inside another, but it doesnt seem to work this way.
If anybody can help me here id be really grateful.
you could create a popup and fill the data on OnCLickListener and then display it.
Have you trying to use show() and hide() for radio button? maybe using a boolean for the parameter show() and hide()

Java setting button values on memory game

I have been working on a memory game i asked a question about yesterday, I got some brilliant suggestions but none of them seem to be helping my problem i can get the buttons to shuffle around the grid layout fine, but i cannot figure out how to keep the set values i tried using "setActionCommand" but i don't think this is the way i can do it for matching the values of two buttons within my memory game.
gameBtn[0].setActionCommand("1");
gameBtn[1].setActionCommand("2");
gameBtn[2].setActionCommand("3");
gameBtn[3].setActionCommand("4");
gameBtn[4].setActionCommand("5");
gameBtn[5].setActionCommand("6");
gameBtn[6].setActionCommand("7");
gameBtn[7].setActionCommand("8");
gameBtn[8].setActionCommand("1");
gameBtn[9].setActionCommand("2");
gameBtn[10].setActionCommand("3");
gameBtn[11].setActionCommand("4");
gameBtn[12].setActionCommand("5");
gameBtn[13].setActionCommand("6");
gameBtn[14].setActionCommand("7");
gameBtn[15].setActionCommand("8");
above is how i used the setActionCommand but i cant find out how you would compare them to each other to find a match for example matching club1 to diamond1 and club2 to diamond2. would this not mean i would have to do something like this for every single match i wanted?.
if (gameBtn[0].getActionCommand().equals(gameBtn[8].getActionCommand())){
sameValues();
}
if (gameBtn[1].getActionCommand().equals(gameBtn[9].getActionCommand())){
sameValues();
}
although the above might seem to work as it does not throw any errors im left thinking there must be a more efficient better way to do it i accomplished this at first before i added the shuffle to move the buttons on the grid i was using another list of values, but know its randomized the card on the button no longer actually matches the buttons set value.
have a look at the link at the bottom of the question if you need more information from my last question, Any help would be much appreciated as this has been bugging me for a while know thank you.
link: Java concentrate is there a way to shuffle jbuttons

Memory game - Make the 2 cards disappear after X time

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.

15 puzzle game in java

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.

Categories