想点击文本框的时候 文本框内容制空 不知道错在哪 (两处报错)

import  不缺

public class Login extends JDialog {

    boolean flag= false;
    DatabaseLink dbc;
    Vector ve;
    JLabel lblWelcome = new JLabel();
    JLabel lblPassword = new JLabel();
    JLabel lblID = new JLabel();
    JComboBox cboID = new JComboBox();
    JPasswordField pawPassword = new JPasswordField();
    JButton btnCancel = new JButton();
    JButton btnOK = new JButton();
    JLabel lblIcon = new JLabel();
    JTextField txtID = new JTextField();

    public Login(DatabaseLink dbc) {
        try {
            this.dbc=dbc;
            setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            jbInit();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        this.setTitle("");
        this.getContentPane().setLayout(null);
        this.getRootPane().setDefaultButton(this.btnOK);
        

        
      /*  cboID.setFont(new java.awt.Font("宋体", Font.PLAIN, 15));
        cboID.setToolTipText("人员编号");
        cboID.setBounds(new Rectangle(135, 60, 140, 30));
        cboID.setEditable(true);*/
        
        txtID.setFont(new java.awt.Font("Dialog", Font.PLAIN, 13));
        txtID.setToolTipText("登录账号");
        txtID.setText("--请输入登录账号--");
        txtID.setBounds(new Rectangle(125, 130, 130, 30));
        txtID.addMouseListener(new Login_txtID_mouseAdapter(this));
       

        this.getContentPane().add(lblID);
       // this.getContentPane().add(cboID);
        this.getContentPane().add(lblPassword);
        this.getContentPane().add(pawPassword);
        this.getContentPane().add(btnCancel);
        this.getContentPane().add(btnOK);
        this.getContentPane().add(lblWelcome);        
        this.getContentPane().add(txtID);

        ve = dbc.getInfo("select UID from employee order by UID");//从数据库中返回所有的人员编号
        for (int i = 0; i < ve.size(); i++) {
            cboID.addItem(ve.get(i));
//向JComboBox中添加人员编号
        }
    }

    public void btnOK_actionPerformed(ActionEvent e) {
        int id = cboID.getSelectedIndex();
        if(id==0){
            JOptionPane.showMessageDialog(this, "请输入人员编号。", "账号有误",
                                          JOptionPane.ERROR_MESSAGE);
            return;
        }
        String str_ID = (String) cboID.getSelectedItem();
        String str_Password = String.valueOf(pawPassword.getPassword());
        String[] re = new String[2];
        re = dbc.passwordValidate(str_ID);
        if ( str_Password.equals(re[1] )) {//登陆成功
            NowUser.userID = str_ID;
            NowUser.userPower = re[0];
            NowUser.password = str_Password;
            flag = true;
            this.dispose();

    


     public void txtID_mouseClicked(MouseEvent e) {
                if (txtID.getText().equals("--请输入登录账号--")) {
                    txtID.setText("");                                             //   报错Multiple markers at this line
   txtID_mouseClicked                }                                       //      - Duplicate local variable e
                                                                                             //   - Syntax error on token "(", ; expected
                                                                                              //   - void is an invalid type for the variable
            }
            
 
            MainFrame frame = new MainFrame(dbc);
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            Dimension frameSize = frame.getSize();
            screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            frameSize = frame.getSize();
            if (frameSize.height > screenSize.height) {
                frameSize.height = screenSize.height;
            }
            if (frameSize.width > screenSize.width) {
                frameSize.width = screenSize.width;
            }
            frame.setLocation((screenSize.width - frameSize.width) / 2,
                              (screenSize.height - frameSize.height) / 2);
            frame.setVisible(true);

        } else {
            JOptionPane.showMessageDialog(this, "请输入正确的密码。", "密码错误",
                                          JOptionPane.ERROR_MESSAGE);
            pawPassword.selectAll();
            pawPassword.requestFocus(true);
        }
    }

    public void btnCancel_actionPerformed(ActionEvent e) {
        System.exit(0);
    }


}

class Login_btnOK_actionAdapter implements ActionListener {
    private Login adaptee;
    Login_btnOK_actionAdapter(Login adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.btnOK_actionPerformed(e);
    }
}


class Login_btnCancel_actionAdapter implements ActionListener {
    private Login adaptee;
    Login_btnCancel_actionAdapter(Login adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.btnCancel_actionPerformed(e);
    }
}

class Login_txtID_mouseAdapter extends MouseAdapter {
    private Login adaptee;                                                     //报错The method txtID_mouseClicked(MouseEvent) is                                                                                                     undefined for the type Login                                                                                                                                   //    Login_txtID_mouseAdapter(Login adaptee)

{
        this.adaptee = adaptee;
    }

    public void mouseClicked(MouseEvent e) {
        adaptee.txtID_mouseClicked(e);
    }
}

启文羊习
浏览 1472回答 1
1回答

扬州灬炒饭

截图要比你这大段截代码效果好一点.....用于页面构建和控件呈现的代码就没必要贴出来了,把  相关控件的 变量名 和 点击事件里的业务逻辑代码贴出来就好了。你这一长串,并不知道重点是个啥
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java