精華區beta java 關於我們 聯絡資訊
小弟是新手 目前需要用java來做我的專題 我目前利用ip camera要來達成機器人視野 我想到利用thread去不斷的讀取ip camera的snapshot 在利用repain()不斷的去刷新 來達成看起來像連續的畫面 但是我不知道為什麼 我的image一直都會是空的 以下是我的片斷程式碼 public class PaintPanel extends JPanel implements Runnable{ String url="192.168.1.102:88/image/image.jpg"; BufferedImage image; URLConnection con; JFrame frame; public PaintPanel(){ } public void getImage(){ try{ URL u = new URL(url); con = u.openConnection(); this.image = ImageIO.read(u); this.repaint(); }catch(Exception e){ JOptionPane.showMessageDialog(null, "Image exception code: "+e); } } @Override public void run(){ try{ for(int i=0; i<=10; i++){ getImage(); this.repaint(); } }catch(Exception e){ } } @Override public void paintComponent(Graphics g){ if(image != null){ System.out.println("image is not null "); g.drawImage(image, 0, 0, this); } else{ System.out.println("image is null!!"); } } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 76.174.193.117