Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Kristjan Toots
Ranch Hand
Posts: 59
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kristjan Toots
Ranch Hand
Posts: 59
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

 
Greg Brannon
Bartender
Posts: 563
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic