在登陆窗口中建立函数: public static boolean isAdministrator(){ if (privilege.equalsIgnoreCase("0"))return true; else return false; } privilege也是static的。 然后在主程序中建立: if (new LoginFrame().isAdministrator()){ //你要执行的操作 } 这样子就解决问题了
我还是把我的代码给你吧。呵呵 /* * LoginFrame.java * * Created on 2004年7月28日, 下午3:57 */package Autosale;import java.sql.*; /** * * @author user */ public class LoginFrame extends javax.swing.JFrame {
/** Creates new form LoginFrame */ public LoginFrame() { initComponents(); }
/** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ private void initComponents() { yongHuBianHaoLabel = new javax.swing.JLabel(); yongHuBianHaoTextField = new javax.swing.JTextField(); miMaLabel = new javax.swing.JLabel(); okButton = new javax.swing.JButton(); jButton1 = new javax.swing.JButton(); miMaPasswordField = new javax.swing.JPasswordField(); getContentPane().setLayout(null); setTitle("\u8bf7\u767b\u9646"); setResizable(false); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { exitForm(evt); } }); yongHuBianHaoLabel.setText("\u7528\u6237\u7f16\u53f7"); getContentPane().add(yongHuBianHaoLabel); yongHuBianHaoLabel.setBounds(30, 10, 60, 20); getContentPane().add(yongHuBianHaoTextField); yongHuBianHaoTextField.setBounds(120, 10, 100, 20); miMaLabel.setText("\u5bc6\u7801"); getContentPane().add(miMaLabel); miMaLabel.setBounds(30, 40, 60, 20); okButton.setText("OK"); okButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { okButtonActionPerformed(evt); } }); getContentPane().add(okButton); okButton.setBounds(30, 70, 80, 20); jButton1.setText("Cancle"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); getContentPane().add(jButton1); jButton1.setBounds(140, 70, 80, 20); getContentPane().add(miMaPasswordField); miMaPasswordField.setBounds(120, 40, 100, 20); java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); setBounds((screenSize.width-250)/2, (screenSize.height-130)/2, 250, 130); }
那你就启动主界面的同时,启动一个JDIALOG的子类,然后把这个JDIALOG 的属性
就是这个... S=NEW ....();
S.SETM...(TRUE);
他就在你的主界面的最上面了!这说明白了不!!!
public static boolean isAdministrator(){
if (privilege.equalsIgnoreCase("0"))return true;
else return false;
}
privilege也是static的。
然后在主程序中建立:
if (new LoginFrame().isAdministrator()){
//你要执行的操作
}
这样子就解决问题了
/*
* LoginFrame.java
*
* Created on 2004年7月28日, 下午3:57
*/package Autosale;import java.sql.*;
/**
*
* @author user
*/
public class LoginFrame extends javax.swing.JFrame {
/** Creates new form LoginFrame */
public LoginFrame() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {
yongHuBianHaoLabel = new javax.swing.JLabel();
yongHuBianHaoTextField = new javax.swing.JTextField();
miMaLabel = new javax.swing.JLabel();
okButton = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
miMaPasswordField = new javax.swing.JPasswordField(); getContentPane().setLayout(null); setTitle("\u8bf7\u767b\u9646");
setResizable(false);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
}); yongHuBianHaoLabel.setText("\u7528\u6237\u7f16\u53f7");
getContentPane().add(yongHuBianHaoLabel);
yongHuBianHaoLabel.setBounds(30, 10, 60, 20); getContentPane().add(yongHuBianHaoTextField);
yongHuBianHaoTextField.setBounds(120, 10, 100, 20); miMaLabel.setText("\u5bc6\u7801");
getContentPane().add(miMaLabel);
miMaLabel.setBounds(30, 40, 60, 20); okButton.setText("OK");
okButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okButtonActionPerformed(evt);
}
}); getContentPane().add(okButton);
okButton.setBounds(30, 70, 80, 20); jButton1.setText("Cancle");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
}); getContentPane().add(jButton1);
jButton1.setBounds(140, 70, 80, 20); getContentPane().add(miMaPasswordField);
miMaPasswordField.setBounds(120, 40, 100, 20); java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-250)/2, (screenSize.height-130)/2, 250, 130);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
executeFlag = true;
if (yongHuBianHaoTextField.getText().length()!=0)executeFlag = new InputCheck().numberCheck(yongHuBianHaoTextField.getText());
if (!executeFlag)new ErrorMsgFrame().getErrorIndex(0);
else{
if (executeFlag){
DBOperation db = new DBOperation("Frank","");
SQLString = null;
SQLString = "select caozuoyuan_Password, caozuoyuan_Level from manager_table where caozuoyuan_Num=" + yongHuBianHaoTextField.getText();
try{result = db.executeQuery(SQLString);
while(result.next()){
if (miMaPasswordField.getText().equals(result.getString("caozuoyuan_Password"))) {
privilege = result.getString("caozuoyuan_Level");
new AutoSaleFrame().show();
setVisible(false);
dispose();
}
else {new ErrorMsgFrame().getErrorIndex(2);
}}}
catch(java.sql.SQLException se){}
}
else {new ErrorMsgFrame().getErrorIndex(2);}}
}
public static boolean isAdministrator(){
if (privilege.equalsIgnoreCase("0"))return true;
else return false;
}
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
new LoginFrame().show();
}
public static String privilege = "";
private String SQLString;
private boolean executeFlag;
private ResultSet result;
// 变量声明 - 不进行修改
private javax.swing.JButton jButton1;
private javax.swing.JLabel miMaLabel;
private javax.swing.JPasswordField miMaPasswordField;
private javax.swing.JButton okButton;
private javax.swing.JLabel yongHuBianHaoLabel;
private javax.swing.JTextField yongHuBianHaoTextField;
// 变量声明结束
}
其实主要就是我前面那帖说的了
祝你好运