在URL中获取图像(Getting image in URL)

编程入门 行业动态 更新时间:2024-10-11 15:18:52
在URL中获取图像(Getting image in URL)

有什么问题,我无法下载图像而不保存在硬盘驱动器上

try { sentenceLabel= new JLabel(new ImageIcon(ImageIO.read(new URL("http://www.google.ru/intl/en_com/images/logo_plain.png")))); } catch (MalformedURLException ex) { // TODO Auto-generated catch block ex.printStackTrace(); } catch (IOException ex) { // "http://img.yandex.net/i/wiz"+imgType.trim()+".png" ex.printStackTrace(); }

怎么了? 抱歉没有问题

What's trouble, I can't download image without saving on Hard Disk Drive by

try { sentenceLabel= new JLabel(new ImageIcon(ImageIO.read(new URL("http://www.google.ru/intl/en_com/images/logo_plain.png")))); } catch (MalformedURLException ex) { // TODO Auto-generated catch block ex.printStackTrace(); } catch (IOException ex) { // "http://img.yandex.net/i/wiz"+imgType.trim()+".png" ex.printStackTrace(); }

What's wrong? Sorry for noob question

最满意答案

你的代码完全没问题。 这将向我显示内容窗格中的图像。

JFrame frame = new JFrame(); frame.setTitle("Polygons"); frame.setSize(550, 550); Container contentPane = frame.getContentPane(); try { JLabel sentenceLabel= new JLabel(new ImageIcon( ImageIO.read(new URL( "http://www.google.ru/intl/en_com/images/logo_plain.png")))); contentPane.add(sentenceLabel); } catch (MalformedURLException ex) { // TODO Auto-generated catch block ex.printStackTrace(); } catch (IOException ex) { // "http://img.yandex.net/i/wiz"+imgType.trim()+".png" ex.printStackTrace(); } frame.show();

Your code is completely fine. This shows me the image in the content pane.

JFrame frame = new JFrame(); frame.setTitle("Polygons"); frame.setSize(550, 550); Container contentPane = frame.getContentPane(); try { JLabel sentenceLabel= new JLabel(new ImageIcon( ImageIO.read(new URL( "http://www.google.ru/intl/en_com/images/logo_plain.png")))); contentPane.add(sentenceLabel); } catch (MalformedURLException ex) { // TODO Auto-generated catch block ex.printStackTrace(); } catch (IOException ex) { // "http://img.yandex.net/i/wiz"+imgType.trim()+".png" ex.printStackTrace(); } frame.show();

更多推荐

本文发布于:2023-07-30 13:49:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1338841.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   URL   image

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!