2016-04-08 13 views
0

ゲームを作成しているときにプレイヤーをリストに追加するためにJComboBoxを作成しました。私はJOptionPaneを使ってエラーメッセージを表示しようとしていますが、テキストフィールドが空のままになっていると、私は以下の方法でこれを行いました。JComboボックスの空のテキストフィールドのエラーメッセージ

btnAddPlayer = new JButton("Add Player"); 
    btnAddPlayer.addActionListener(new ActionListener() { //This is the layout for the list of points that are possible to achieve 
     public void actionPerformed(ActionEvent arg0) {  
      if (txtAddPlayer.equals("")){ 
         JOptionPane.showMessageDialog(btnAddPlayer, this, "Please Enter Full Details", NumofAnswers);//THIS IS THE METHOD I TRIED 
       } else { 
        comboBox.addItem(txtAddPlayer.getText()); 
       } 
     } 
    }); 
    btnAddPlayer.setBounds(469, 243, 89, 23); 
    panel.add(btnAddPlayer); 
    txtAddPlayer = new JTextField(); 

    txtAddPlayer.setBounds(373, 244, 86, 20); 
    panel.add(txtAddPlayer); 
    txtAddPlayer.setColumns(10); 

なぜこれが機能しないのかわかりません。私のコードを使って答えを提供してください。 (textField.gettext()。等号( ""))場合

+0

場合(txtAddPlayer.length()<0) –

+0

だから何が起こる_does_? – Mordechai

+0

エラーメッセージは表示されず、空のコンポーネントがリストに追加されます –

答えて

0

は であるべき よろしく、

関連する問題