This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
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.
Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
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?
Joined: Oct 24, 2010
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.