Java Reference
In-Depth Information
public ImageClient()
{
try
{
host = InetAddress.getLocalHost();
}
catch(UnknownHostException uhEx)
{
System.out.println("Host ID not found!");
System.exit(1);
}
try
{
Socket connection = new Socket(host,PORT);
//Step 3…
ObjectInputStream inStream =
new ObjectInputStream(
connection.getInputStream());
//Steps 4 and 5…
image = (ImageIcon)inStream.readObject();
//Remember to close the socket…
connection.close();
}
catch(IOException ioEx)
{
ioEx.printStackTrace();
}
catch(ClassNotFoundException cnfEx)
{
cnfEx.printStackTrace();
}
//Now cause the paint method to be invoked…
repaint();
}
public void paint(Graphics g)
{
//Defi ne paint to display the image
//upon the application frame…
image.paintIcon(this,g,0,0);
}
}
(Note that, though meaningful variable names are very much to be encouraged,
the use of variable name 'g' above (a) is very common practice and (b) cannot really
be misinterpreted, since it is glaringly obvious what it represents.)
Search WWH ::




Custom Search