Forums Register Login

How to approach to disable or enable JButtons regarding user access status?

+Pie Number of slices to send: Send
Hello,
I'm trying to create a simple GUI with couple of buttons and 2 different users. I would like to use the same GUI for "user" and "admin" where some of those buttons are disabled for "user".
I have imagined that I would create a template GUI with all the buttons and on run-time it will decide whether to disable certain buttons or not to.

I am a bit stuck coming up with proper solution since I don't quite know how to approach.

* I have thought about using 2D arrays where I add the button to the 1st dimension and I would use the 2nd dimension for deciding whether to enable or disable the button. Afterwards I would add those buttons to the JPanel from the array.

* I have thought about creating 2 classes (user & admin) where user has int value as "accessLevel" and admin extends from it and re-writes it with different value. Then I would use that "accessLevel" value to determine whether to disable or not to.

I would really appreciate some pseudo code or some other pointers how should I approach the given problem.
+Pie Number of slices to send: Send
Or a single User class that has a field that can be set for multi-level access, even if it's just two levels, admin and regular. Then, when a user logs in, the GUI will be set to reflect that person's access. The right buttons will be turned on, the others turned off, etc.
+Pie Number of slices to send: Send
Thank you Sir for taking the time to reply.
I am not familiar with those topics, is it too much to ask for some key terms or some pointers to the required reading material?

1
+Pie Number of slices to send: Send
I suggest you start by reading up on how to use JButtons here. Or, if this your first Java GUI project, you should start at this page. Oracle is pushing the use of Netbeans GUI Builder, but I recommend you ignore that part and learn to code Swing by hand. It's not as challenging as they suggest.

Come back and ask questions as you need more help.
+Pie Number of slices to send: Send
 

Greg Brannon wrote:Oracle is pushing the use of Netbeans GUI Builder, but I recommend you ignore that part and learn to code Swing by hand. It's not as challenging as they suggest.



It's a greater challenge to learn the quirks of the visual designer, and especially so when you don't know what the auto-generated code does.
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1749 times.
Similar Threads
B&S: Passed 373/400
how to disable a button on onclick of radio button
JButtons should start Threads whit synchronized handling of a JTable model
Errors in GUI program
Which Container should I use?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:39:18.