/* * Main.java * * Created on Sep 5, 2007, 11:17:20 AM * * To change this template, choose Tools | Templates * and open the template in the editor. */ package flowerclient; import java.awt.Image; import flower.client.IOException_Exception; import java.util.HashMap; import java.util.List; import java.util.Map; /** * * @author mkuchtiak */ public class Main { private static int downloadedPictures; /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here final Map flowers = new HashMap(4); final Map thumbs = new HashMap(4); final FlowerFrame frame = new FlowerFrame(flowers); frame.setVisible(true); flower.client.FlowerService_Service service = new flower.client.FlowerService_Service(); final flower.client.FlowerService port = service.getFlowerServicePort(); Runnable[] tasks = new Runnable[4]; // the web service getFlower(String "flowerName") operation is called 4 times, // each WS call runs in a separate thread. // When the operation finishes the picture is shown in particular frame panel. for (int i=0; i<4;i++) { final int index = i; tasks[i] = new Runnable() { public void run() { try { Image img = port.getFlower(FlowerFrame.FLOWERS[index]); System.out.println("picture downloaded: "+FlowerFrame.FLOWERS[index]); flowers.put(FlowerFrame.FLOWERS[index],img); frame.showFlower(); } catch (IOException_Exception ex) { ex.printStackTrace(); } downloadedPictures++; } }; new Thread(tasks[i]).start(); } // the web service getThumbnails() operation is called in a separate thread, // just after previous 4 threads finish // When the images are downloaded the thumbnails are shown at the bottom of the frame. Runnable thumbsTask = new Runnable() { public void run() { try { while (downloadedPictures < 4) { try {Thread.sleep(100);} catch (InterruptedException ex) {} } List images = port.getThumbnails(); System.out.println("thumbs downloaded"); if (images != null && images.size() == 4) { for (int i=0;i<4;i++) { thumbs.put(FlowerFrame.FLOWERS[i],images.get(i)); } frame.setThumbnails(thumbs); } } catch (IOException_Exception ex) { ex.printStackTrace(); } } }; new Thread(thumbsTask).start(); } }