Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+12 votes

In our program we have 2 different buttons for the different ways to type CW, one being for paddles and the other being a straight key. Is there a way to prevent the user from being able to click one? Or is there a better component to use instead of buttons? I want to do this because I do not want the user to be able to select the mode that they are already in.

asked in CSC 305 Fall 2024 by (594 points)

3 Answers

+6 votes

You can manage two buttons for "Paddle Mode" and "Straight Key Mode" by disabling the button that corresponds to the current active mode (I believe the function is setDisable()). In your controller, use a variable, such as currentMode, to keep track of the active mode. Each button’s action handler checks if the mode is already selected; if not, it updates currentMode and calls a method, like updateButtonState, which disables the button of the active mode, providing a clear visual indication to the user. This prevents redundant selection and makes it easy to toggle between modes, giving users feedback on which mode is active.

answered by (4.4k points)
+6 votes

Something you could consider (in trying to work smarter not harder - I’m sure you could figure out how to make two buttons work, but I don’t know whether it will end up feeling like it was worth the effort or not) - do you actually need to have two buttons? Or could you just have a checkbox that toggles to “Paddle mode” and in your initial instructions, say that the default option is a straight key? Then you would only have one fx component to work with, and you could use a simple Boolean to just check the status of the checkbox. Not sure exactly what your goal is but thought I’d give that as an easy workaround.

answered by (4.5k points)
+5 votes

One way that I can think about accomplishing this is to add an if statement to the button's activation. If you can save the "mode" inside a variable, you can put an if statement inside the method that it's calling.

For instance, if the mode paddles were selected, then set the variable to true. If the paddles are pressed, the method should run a check to see if the variable is true (and if it is, run it).

One other way that I can think of is to make two separate windows (one with paddles, one with the key) and when the mode is selected, take the user to that window. This has the benefit of allowing the programmer to prevent the other "control" from existing in each respective window but might be less efficient and bulkier.

answered by (2k points)
...