2017-05-09 5 views
0

私はGameHelp()を自分のGameクラスに持っていて、それを私のGameGUIクラスのtextPaneに表示しようとしています。 printHelp()がvoid型を返すため、エラーメッセージが表示されます。誰にでも提案がありますか?どうもありがとう!textPaneにsystem.out.print()を表示する方法

JTextPane textPane = new JTextPane(); 
contentPane.add(textPane, BorderLayout.CENTER); 
textPane.replaceSelection("whatever printed in printHelp() needs to be displayed here."); 


protected void printHelp() 
{ 
    System.out.println("You are lost. You are alone. You wander"); 
    System.out.println("around at the university."); 
    System.out.println(""); 
    System.out.println("Your command words are:"); 
    parser.showCommands(); 
} 
+0

エラーメッセージは何ですか? –

答えて

0

これにより、あなたのprintHelpメソッドを置き換えます

protected String printHelp() 
{ 
    String message = "You are lost. You are alone. You wander" 
    +"\n"+"around at the university." 
    +"\n" 
    +"\n"+"Your command words are:"; 
    message += parser.showCommands(); 
    return message; 
} 

そして:

​​

あるいは必要に応じて、使用:

private void printBoth() { 
    String message = printHelp(); 
    textPane.replaceSelection(message); 
    System.out.println(message); 
} 
関連する問題