Credits

Wednesday, August 10, 2011

User - Level Access in Java



Main program with deactivated File and Reports and shortcut buttons for common user access only.

login form for user - type "User/Administrator"

It is  possible to have user - level access in Java.Depending on the user type whether he is an ordinary  user or administrator would tell the level access.

For an ordinary user, he can only access transactions where for this instance of a business application, sales, expenses and payments are only the options allowed.

This kind of operation requires us to deactivate menu items or shortcut buttons. The program below illustrates this example.

[+/-] show/hide



/** Creates new form MainProgram */
public MainProgram(String xusername,String xusertype) {
initComponents();
this.username=xusername;
this.usertype=xusertype;
MainProgramStatus(); //to de/activate menu options
lblusername.setText(this.username);
setExtendedState(JFrame.MAXIMIZED_BOTH);


}
:
:

public void MainProgramStatus(){
//to activate / deactivate menu options for user type
if (usertype.equals("User"))
{ mFile.setEnabled(false);
mReports.setEnabled(false);
jButton1.setEnabled(false);
jButton4.setEnabled(false);}
else
{
mFile.setEnabled(true);
mReports.setEnabled(true);
jButton1.setEnabled(true);
jButton4.setEnabled(true);}
}

AddThis