在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();更多推荐
发布评论