我想让 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/