I'm trying to use user management levels in my java swing project. I want to disable few buttons to users which only admin can click. So in my project I designed my home page using JFrame. And I have few buttons called Stock, Invoice, Grn etc..
In each button I changed access level as "public" by using properties==> cord==> Variable modifiers.
But in Home JFrame I couldn't change the access level as "public".
In my login frame I when I'm logging as a user I want to code like given below. But still I can't call Home.hm.btnStock because I can't change the user level of Home.
In login interface
LogToHome lh = new LogToHome();
public static Login log;
private void btnLoginActionPerformed(java.awt.event.ActionEvent evt) {
lh.logHome(comboUn, jpass);
}
in LogToHome java class
public void logHome(JComboBox combo, JPasswordField jpass) {
if (combo.getSelectedItem().equals("--SELECT--")) {
JOptionPane.showMessageDialog(null, "Select User name");
} else if (jpass.getText().isEmpty()) {
JOptionPane.showMessageDialog(null, "Insert your Password");
jpass.grabFocus();
} else {
try {
String un = combo.getSelectedItem().toString();
String pass = new String(jpass.getPassword());
ResultSet rs = new JDBC().getData("SELECT * FROM login WHERE un='" + un.trim() + "' AND pw='" + pass + "'");
if (rs.next()) {
JOptionPane.showMessageDialog(null, "Login OK");
Login.log.setVisible(false);
if (un == "user") {
Home.hm = new Home();
Home.hm.btnStock.setenabled(false);
Home.hm.setVisible(true);
} else {
Home.hm = new Home();
Home.hm.setVisible(true);
}
} else {
JOptionPane.showMessageDialog(null, "Enter valid user name or password");
jpass.setText("");
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, this.getClass().getName() + " " + e);
}
}
}
}