【发布时间】:2014-04-16 21:47:28
【问题描述】:
遇到了一个问题,希望有人能帮我解决。我在我的程序中使用了一个 JOptionPane,但是当我运行这个类时,第一个 JOptionPane 会在后台弹出,所以你在 eclipse 中看不到它,直到你 alt + tab 并找到它。
我如何得到它以便它在前面运行?
我的 GUI 类代码,它将创建我的窗格。
import java.io.IOException;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JFrame;
public class GUI {
@SuppressWarnings("unused")
public void getConfirmation() throws IOException {
JFrame frame = new JFrame();
Object[] options = {"Continue","Stop procedure"};
int n = JOptionPane.showOptionDialog(frame,
"Would you like to continue or stop procedure?",
"Plese confirm",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[0]);
frame.toFront();
frame.repaint();
if(JOptionPane.YES_OPTION == 1) {
// Program will keep going
}
else if (JOptionPane.NO_OPTION == 0) {
System.out.println(" ");
System.out.println("Procedure terminated");
System.out.println(" ");
}
}
}
我从另一个类运行 GUI 类,如下所示:这里您可以看到我的客户端类中的一些代码。
System.out.println("You received " + fromServer + " from the server");
System.out.println("Please answer confirmationbox" + "\n\n");
GUI.getConfirmation();
但我发现,它只是第一次运行它会在后台启动,之后当我再次尝试运行它时,我会正常运行。
【问题讨论】:
-
它对我来说工作正常。也请分享入门课程。
-
oki,我会更新我的帖子,30秒后签到
-
getConfirmation方法不是静态的。你不能说GUI.getConfirmation();。请确认。
标签: java