Java中是否有多输入JOptionPane?

发布于 2024-07-09 07:15:44 字数 133 浏览 4 评论 0原文

我想知道是否有一个 JOptionPane 可以从用户那里获取多个输入,而不仅仅是一个? 如果没有,我如何使用某种类型的提示来完成此操作。 我正在创建战舰,并希望提示用户指定放置每艘船的位置。

谢谢,

托梅克

I was wondering if there is a JOptionPane where you can get multiple inputs from a user instead of just one? If not, how could i accomplish this using some type of prompt. I am creating Battleship, and wanted to prompt the user to specify locations to place each ship.

Thanks,

Tomek

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鸠魁 2024-07-16 07:15:44

作为消息传递到 JOptionPane 的对象可以是图形组件,因此类似这样的内容应该可以工作:

JPanel panel = new JPanel();
// Populate your panel components here.
int ret = JOptionPane.showConfirmDialog(parent, panel, "Title", JOptionPane.YES_NO_OPTION);
if ( ret == JOptionPane.YES_OPTION )
{
  // Read component values.
}

The object that you pass in as the message to the JOptionPane can be graphical components, so something like this should work:

JPanel panel = new JPanel();
// Populate your panel components here.
int ret = JOptionPane.showConfirmDialog(parent, panel, "Title", JOptionPane.YES_NO_OPTION);
if ( ret == JOptionPane.YES_OPTION )
{
  // Read component values.
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文