0

netbeans で記述された次のコードは、コンボ ボックスに属する各ユーザーを system.ones にログインすることを想定しています。

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 に答える