Java Reference
In-Depth Information
image format. There's nothing REST-specific about it, but I show it here for completeness
( Example 8-15 ) .
Example8-15.ImageViewer.java displays the image retrieved by the client
package com.soacookbook.rest.ex;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
/**
* Shows an image in a window given a file path.
* Used by the DifferentRepClient class to prove the client
* got the image.
*/
public class ImageViewer {
final private JFrame frame = new JFrame("Image Viewer");
//constructor reads image and sets up frame
public ImageViewer(String fileLocation) {
try {
//read newly saved image file
File input = new File(fileLocation);
BufferedImage image = ImageIO.read(input);
//set up window
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//put image on it
Icon icon = new ImageIcon(image);
JLabel label = new JLabel(icon);
frame.getContentPane().add(
label, BorderLayout.CENTER);
//make image fit window
frame.pack();
//now it's all set to show
Search WWH ::




Custom Search