0

用netbeans编写的以下代码假设将属于组合框的每个用户记录到系统中。用户名、密码和As是匹配的,但是在将组合框中的值分配为登录标准时遇到问题

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)       

{
    String inputusername = jTextField1.getText();
    String inputpassword = jPasswordField1.getText();
    String inputAs = jComboBox2.getText();
    if(inputusername.trim().length() == 0 ||
            (inputpassword.trim().length() == 0) ||
            (inputAs.trim().length() == 0)) {
        JOptionPane.showMessageDialog(this,"Error.", "Incomplete Fields", 
 JOptionPane.WARNING_MESSAGE);
    }else{

        Login l = new Login(inputusername,inputpassword,inputAs);
        jTextField3.setText(l.Log());
4

1 回答 1

1

你会使用:

if (jComboBox.getSelectedItem.equals("name of one item in list")

因此,如果您有一个 jComboBox 名称 planetsCombo 列出行星,并且您想为地球制定标准,它会说:

if (planetscombo.getSelectedItem.equals("Earth")

希望我有所帮助!

于 2012-12-02T20:38:19.157 回答