我想抓取來自在線的圖像,然後用它在Jframe表單上顯示。 「你好,世界!」將顯示,但圖像不會顯示。任何想法傢伙?乾杯。Java圖像抓取和顯示
JFrame frame = new JFrame();
frame.setSize(400, 400);
JLabel label = new JLabel("Hello, World!");
String path = "http://chart.finance.yahoo.com/z?s=GOOG&t=6m&q=l";
try {
URL url = new URL(path);
ImageIcon image = new ImageIcon(url);
JLabel imageLabel = new JLabel(image);
label.setOpaque(true);
frame.add(imageLabel);
frame.add(label);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
} catch (MalformedURLException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
請在此處查看[問] - 如果有任何問題或需要告訴我們沒有任何問題,請填寫錯誤信息。 –