Java Reference
In-Depth Information
InputStream is = httpurlc.getInputStream();
byte[] bytes = new byte[10000];
int b, i = 0;
while ((b = is.read()) != -1)
{
bytes[i++] = (byte) b;
if (i == bytes.length)
{
byte[] bytes2 = new byte[bytes.length*2];
System.arraycopy(bytes, 0, bytes2, 0, i);
bytes = bytes2;
}
}
byte[] bytes2 = new byte[i];
System.arraycopy(bytes, 0, bytes2, 0, i);
return new ImageIcon(bytes2);
}
throw
new
IOException("http
error:
"+ht-
tpurlc.getResponseCode());
}
catch (IOException e)
{
JOptionPane.showMessageDialog(null,
e.getMessage(), "viewchart",
JOp-
tionPane.ERROR_MESSAGE);
return null;
}
}
}
Listing11-15 isfairlystraightforward.Its main() methodinvokes doGet() with
the query string. If this method returns a javax.swing.ImageIcon object, a
Swing-basedframewindowiscreated,thiswindowistoldtoterminatetheapplication
whentheuserclickstheXbuttononthewindow'stitlebar(forWindowsandsimilarop-
eratingsystems),alabelbasedontheiconiscreatedandassignedtotheframewindow
asitscontentpane,thewindowis packed (sizedtothepreferredsize)ofthelabel(which
Search WWH ::




Custom Search