- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
正如我的标题所述,每当我调用它时,我的 showConfirmDialog 都不会等待按下"is"或“否”按钮。
最初我遇到了一个错误,导致我获得空白的 JOptionPanes
,所以现在我使用 invokeLater
方法。我对这个概念不太熟悉,所以我提前道歉。
public int firstGame()
{
SwingUtilities.invokeLater(new Runnable() {
public void run() {
yOrN = JOptionPane.showConfirmDialog(null,
"Are you ready to play?\n", "Play?", JOptionPane.YES_NO_OPTION);
}
});
return yOrN;
// will return 0 if yes and 1 if no.
}
在使用invokeLater
之前,它工作正常(除了空白的JOptionPane
)。这个方法是否运行另一个线程?为什么我的 showInputDialog
等待输入而不是这个?
最佳答案
SwingUtilities.invokeLater
就是这样做的,它将 Runnable
放入事件队列中以便稍后运行,这意味着一旦您调用它,您的 return
语句几乎在它之后立即执行,并且在将来的某个时间,将显示 JOptionPane
。
此类请求被放入事件队列并由事件调度线程处理
看看How to pass results from EDT back to a different thread?寻找可能的解决方案...
关于java - JOptionPane.showConfirmDialog 不停止当前线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19288269/
我正在使用 JOptionPane 来获取字符串。单击“确定”即可保存字符串。现在我希望弹出第二个 JOptionPane 以输入第二个必要的字符串。是否有机会将 ActionListener 添加到
我有一个显示来自 JOptionPane 的确认消息的过程。此过程从 JMenuItem 的 Actionlistener 内的 SwingUtilities.invokeLater(runnable
我使用以下代码来获取InputDialog: String c = JOptionPane.showInputDialog("Select number",JOptionPane.OK_OPTION)
正如你从我上面的主题中看到的, 我想知道我怎么能解雇一个 JOptionPane 因为另一个 JOptionPane 而变得无关紧要,因为用户出于某种原因没有通过自己点击确定按钮(例如)解雇第一个。
没有收到“文件已成功接收”消息,请帮助我。将文件从客户端传输到服务器时,即使文件已收到,也不会显示该消息。 这是使用套接字将文件从客户端传输到服务器的程序,接口(interface)也是使用java
JOptionPane.showInputDialog 有一个不需要父组件参数的表单。 JOptionPane.showConfirmDialog 确实如此。这是为什么? 最佳答案 JOptionPa
我正在用 Java 创建一个基于 Tic Tac Toe GUI 的游戏,并且正在努力将 2D 数组与 JOptionPane 结合使用。到目前为止,我已经能够创建可供选择的按钮: import ja
使用 JOprionPane 时,光标出现了一些问题。我将光标设置到 pharent 框架,然后使用这个显示一个对话框: Object[] possibilities = {"ham", "spam"
我创建了一个打开 JOptionPane 的按钮。它允许用户输入 string..>> String str = JOptionPane.showInputDialog 如何获取用户输入到 jopti
该代码正在运行。但问题是,当选择 NO_OPTION 时,窗口就会被释放。我想在选择 NO_OPTION 时保留窗口?你能给点建议吗? int dialogButton = JOptionPa
我正在 Java 上开发 Tic Tac Toe 游戏(eclipse)。在我的计算机上,我的对话框非常小。我一直在努力把它做得更大。我没有任何运气。我希望这里有人能引导我走向正确的方向。下面的代码是
我正在使用脚本 API 为我玩的游戏的机器人制作脚本,但是每当我覆盖机器人管理器时,就会出现一个 JOptionPane 来阻止执行,直到我关闭它,但是我想在不运行该脚本的情况下运行此脚本人为干预,所
我正在用 Java 开发一个游戏,我试图在 JOptionPane 确认框打开时暂停它。这是代码: window.addWindowListener(new WindowAdapter() {
这个问题已经有答案了: Calling one JFrame from another using Timer without any buttons (1 个回答) 已关闭 9 年前。 需要帮助制作
很抱歉代码这么长,我只需要知道我缺少什么来初始化我的所有决定。编译器提示我的变量没有被初始化。谢谢你。 import javax.swing.JOptionPane; public class Sem
我想使用 JOptionPane 处理一些异常。这是主要方法: public class MainRun { public static void main(String args[]){
不允许使用数组,该函数正在工作,但只是返回 0,就好像它没有计算正确的输入字符一样,但现在它给了我一个“字符串超出范围:3” 这应该运行,打开一个窗口,要求我输入一个字符串,在本例中是一个单词,然后打
我正在使用 Jfilechooser,如果我选择文件,它将计算文件名的字符数,但是如果文件超过 3kb,它将限制 Joptionpane 将显示。我的问题是即使文件是0kb,Joptionpane也会
我创建了一个应用于框架的名为 addSupplier 的按钮,然后创建了一个操作监听器,因此一旦按下 addSupplier 按钮,它将创建一个 JOptionPane,其中有一个附加了 JTextF
我知道解决方案是使用 for 循环来逐步遍历数组并显示在 Pane 中。但是我没有找到对此的直接解释。我需要一个下一个和一个上一个按钮来显示每个数组元素,并且在按下下一个按钮时到达第一个元素后仅返回到
我是一名优秀的程序员,十分优秀!