简体   繁体   English

如何将System.out.print从函数显示到JOptionPane.showMessageDialog?

[英]How to display System.out.print from a function to JOptionPane.showMessageDialog?

How can I display the something like following using JOptionPane.showMessageDialog? 如何使用JOptionPane.showMessageDialog显示类似内容? I've tried using with String.format but that doesn't appear to work or I'm either doing it incorrectly. 我试过与String.format一起使用,但这似乎无法正常工作,或者我做错了。

public void Display ()
{
    int size_ = rows_ * columns_;
    for (int i = 1; i <= size_; ++i)
    {
        System.out.print( "* ");
        if (i % columns_ == 0)
        {
            System.out.print( "\n ");
        }
    }
}

Use StringBuilder to build the desired String(using append() ). 使用StringBuilder生成所需的String(使用append() )。 The you can simply call toString() on the StringBuilder instance to get the String and use it in your JOptionPane.showMessageDialog() method. 您只需在StringBuilder实例上调用toString()即可获取String并在您的JOptionPane.showMessageDialog()方法中使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM