Java 如何设置权限
我正在开发登录和注册界面 当用户注册为管理员并以管理员身份登录时,我将进入一个仅为管理员指定的屏幕 当用户以雇员身份注册并以雇员身份登录时,我将进入雇员只使用的屏幕Java 如何设置权限,java,ms-access-2007,Java,Ms Access 2007,我正在开发登录和注册界面 当用户注册为管理员并以管理员身份登录时,我将进入一个仅为管理员指定的屏幕 当用户以雇员身份注册并以雇员身份登录时,我将进入雇员只使用的屏幕 public class Register extends JFrame { public Register() { initComponents(); setTitle("Register"); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); }
public class Register extends JFrame {
public Register() {
initComponents();
setTitle("Register");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
TF1 = new javax.swing.JTextField();
TF2 = new javax.swing.JTextField();
TF3 = new javax.swing.JTextField();
TF4 = new javax.swing.JTextField();
B1 = new javax.swing.JButton();
PF1 = new javax.swing.JPasswordField();
RB1 = new javax.swing.JRadioButton();
RB2 = new javax.swing.JRadioButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
jLabel1.setText("First Name");
jLabel2.setText("Last Name");
jLabel3.setText("Username");
jLabel4.setText("Password");
jLabel5.setText("Email");
B1.setText("Register");
B1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
B1ActionPerformed(evt);
}
});
RB1.setText("Manager");
RB2.setText("Employee");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(22, 22, 22)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING))
.addGap(23, 23, 23)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(TF4)
.addComponent(PF1))
.addGap(51, 51, 51))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(jLabel3)
.addGap(21, 21, 21)
.addComponent(TF3, javax.swing.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(TF2, javax.swing.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE)
.addComponent(TF1))))
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(RB1)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(RB2)
.addGap(161, 319, Short.MAX_VALUE))))
.addGroup(layout.createSequentialGroup()
.addGap(166, 166, 166)
.addComponent(B1)
.addGap(0, 0, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(23, 23, 23)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(TF1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(TF2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(TF3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(TF4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(PF1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(RB1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(RB2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 4, Short.MAX_VALUE)
.addComponent(B1)
.addContainerGap())
);
pack();
}// </editor-fold>
private void B1ActionPerformed(java.awt.event.ActionEvent evt) {
Connection con = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
con = DriverManager.getConnection("jdbc:odbc:Tickets");
Statement stmt = con.createStatement(); //Query statment
stmt.executeUpdate("INSERT INTO Register VALUES ('"+TF1.getText()+"','"+TF2.getText()+"','"+TF3.getText()+"','"+TF4.getText()+"','"+PF1.getText()+"')");
setVisible(false);
} catch (Exception e) {
System.err.println("Exception: "+e.getMessage());
}
}
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Register.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Register.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Register.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Register.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Register().setVisible(true);
}
});
}
只需执行ifuserType.equalsIgnoreCaseemployee{//code使员工页面可见}或者{//make visible login page}但我不知道用户类型会是什么!我的意思是,所有这些都保存在数据库中,要知道他是员工还是管理员,取决于他是如何注册的,方法是在员工或管理员单选按钮上单击“注册”按钮。是的,但是当你存储用户时,你也必须在数据库中保存用户类型。然后从数据库中选择用户类型并检查他/她是什么类型的用户。