Java Reference
In-Depth Information
adoptsthesizeoftheimageicon'simageasitspreferredsize),thewindowismadenon-
resizable, and the window is displayed.
The doGet() methodcreatesa URL object,opensanHTTPconnectiontothe URL
instance,specifies GET astherequestmethod,tellstheconnectionthatitonlywantsto
inputcontent,andproceedstoreadthecontentwhentheresponsecodeis200(success).
The content is stored in an array of bytes. If the array is too small to hold all the
content,thearrayisdynamicallyresizedbycreatingalargerarrayandcopyingtheori-
ginalarray'scontenttothenewarraywithhelpfrom System.arraycopy() .After
allbyteshavebeenread,thisarrayispassedto ImageIcon 's ImageIcon(byte[]
imageData) constructortostorethePNGimageasthebasisofthe ImageIcon ob-
ject, which is returned from doGet() .
Ifsomethinggoeswrong,aninstanceofthe IOException classoroneofitssub-
classes (such as java.net.MalformedURLException , which signifies that the
argument passed to URL 's constructor is illegal) is thrown. The catch block handles
this exception by invoking javax.swing.JOptionPane 's void showMes-
sageDialog(Component parentComponent, Object message,
String title, int messageType) to display a suitable error message via a
popup dialog box.
Compile Listing11-15 ( javac ViewChart.java )andruntheapplication( java
ViewChart ). Figure 11-8 shows the resulting chart.
Search WWH ::




Custom Search