Reputation: 13
Wondering how to delay a JOptionPane. The goal is to get the picture to pop up, then the box, so that the box will always open infront of the default browser.
Code
//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
}
Upvotes: 0
Views: 161
Reputation: 324128
Why are you trying to display the image in a browser?
Just display the image in a JLabel and add the label to a frame. Then you are in full control of the application.
You can use ImageIO
to read an image from a URL:
BufferedImage image = Imagio.read(...);
ImageIcon icon = new ImageIcon( image );
JLabel label = new JLabel( icon );
frame.add( label );
frame.setVisible( true );
// show JOptionPane
Upvotes: 1