想知道如何延迟 JOptionPane。目标是先弹出图片,然后弹出框,以便该框始终在默认浏览器前面打开。
代码
//this is with the bottom thing, probably above the modules
public void openWebPage(String url){
try {
java.awt.Desktop.getDesktop().browse(java.net.URI.create(url));
}
catch (java.io.IOException e) {
System.out.println(e.getMessage());
}
}
private void ResetButtonActionPerformed(ActionEvent e)
{
openWebPage("http://www.rd.com/wp-content/uploads/sites/2/2016/04/01-cat-wants-to-tell-you-laptop.jpg");
//int delay = 1000; //milliseconds [Unused]
String message = "I didn't know how to code a reset button." + "\n";
String message2 = "So have a nice cat instead. -Cakemoth";
JOptionPane.showConfirmDialog(null, message + message2, "Class Registration", JOptionPane.DEFAULT_OPTION,
JOptionPane.INFORMATION_MESSAGE);
// URL : http://www.rd.com/wp-content/uploads/sites/2/2016/04/01-cat-wants-to-tell-you-laptop.jpg
}
最佳答案
为什么要尝试在浏览器中显示图像?
只需在 JLabel 中显示图像并将标签添加到框架中即可。然后您就可以完全控制该应用程序。
您可以使用 ImageIO
从 URL 读取图像:
BufferedImage image = Imagio.read(...);
ImageIcon icon = new ImageIcon( image );
JLabel label = new JLabel( icon );
frame.add( label );
frame.setVisible( true );
// show JOptionPane
关于java - 使用 Web 浏览器延迟 JOptionPane,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43855758/