2017-05-09 25 views
0

我在我的Game类中有一个printHelp(),我试图在textPane的GameGUI类中显示它。我收到了错误消息,因为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); 
} 
相关问题