java - 使 JOptionPane 从网站打开图像时遇到问题

标签 java joptionpane

我想让 JOptionPane 从链接打开图像,因为下周我有一项作业,我必须在 JOptionPane 中包含图像,虽然它适用于本地文件,但我不确定是否会显示当我把它交出来时。无论如何,我所拥有的是:

ImageIcon thing = new ImageIcon("http://i.imgur.com/OGxr68g.jpg");
       String[] finalOutputChoices = {"Help", "Please"};         
   int finalOutput = JOptionPane.showOptionDialog( 
           null                                 // 
           , "Message"                          // 
           , "Final Output"                     // 
           , JOptionPane.YES_NO_OPTION          //
           , JOptionPane.PLAIN_MESSAGE          //
           , thing                              //
           , finalOutputChoices                 // 
           , "Awesome"                          // 
   );

如果我将链接替换为桌面上图像的路径,它可以工作,但不能替换链接。

如有任何帮助,我们将不胜感激:)

最佳答案

使用 URL 对象。

ImageIcon thing = new ImageIcon(new URL("http://i.imgur.com/OGxr68g.jpg"));

PS:奇怪的图像;-)

关于java - 使 JOptionPane 从网站打开图像时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26566747/

相关文章:

java - 如何解决 OS X 的 Maven 对 rt.jar 的依赖?

java - JBoss Netty 中灵活的超时机制?

java - 将 System.out.print 转换为 JOptionPane?

java - 在hibernate3中从日期获取月份的标准

JavaFX:ImageView 不显示大图像

java - 有没有办法为 JOptionPane.showOptionDialog 设置布局?

java - 如何使用 JButton 为 ActionEvent 创建 If 语句

java - 如何在 GUI 中出现另一个 JOptionPane 时关闭一个 JOptionPane

java - 具有有限迭代和 IF 语句的复杂循环

java - 将序列图转换为 Java 代码