2016-10-17 10 views
0

if/else文を使用してJTextフィールドに複数のテキストを出力するにはどうすればよいですか?私は結果ボタンを押すたび私は、複数のテキストをプリントアウトするにはどうすればよい

private void resultActionPerformed(java.awt.event.ActionEvent evt) {          
    // TODO add your handling code here: 
    if(pick1 > pick2){ 
    resultstf.setText("The New President is Koon!"); 
    } 
    else if(pick2 > pick1){ 
    resultstf.setText("The New President is Baam!"); 
    } 
    else if(pick1 == pick2){ 
    resultstf.setText("The Result for the new President is a Tie! Please Vote Again."); 
    } 
    if(pick3 > pick4){ 
    resultstf.setText("The New VP is Sachi!"); 
    } 
    else if(pick4 > pick3){ 
    resultstf.setText("The New VP is Faker!"); 
    } 
} 

?私は「新大統領はKoonです」と同時に「New VP is Sachi」という印刷物を印刷したいと思っています。あなたが一緒に行くように

+0

は、あなたがより多くのオンラインビットを検索しました可能性があります。http :/ /stackoverflow.com/a/15383945/6426617 –

答えて

0

StringBuilder使用してメッセージを構築: - StringBuilder` `の使用は答えをチェックニードフルを行いますだけでなく、質問 -

private void resultActionPerformed(java.awt.event.ActionEvent evt) { 
    StringBuilder message = new StringBuilder();         
    // TODO add your handling code here: 
    if (pick1 > pick2) { 
     message.append("The New President is Koon!\n"); 
    } 
    else if (pick2 > pick1) { 
     message.append("The New President is Baam!\n"); 
    } 
    else if (pick1 == pick2) { 
     message.append("The Result for the new President is a Tie! Please Vote Again.\n"); 
    } 
    if (pick3 > pick4) { 
     message.append("The New VP is Sachi!\n"); 
    } 
    else if (pick4 > pick3) { 
     message.append("The New VP is Faker!\n"); 
    } 

    resultstf.setText(message.toString()); 
} 
+0

感謝のメイト!^_ ^ –

関連する問題