當前位置: 首頁>>代碼示例>>Java>>正文


Java MediaTracker.waitForAll方法代碼示例

本文整理匯總了Java中java.awt.MediaTracker.waitForAll方法的典型用法代碼示例。如果您正苦於以下問題:Java MediaTracker.waitForAll方法的具體用法?Java MediaTracker.waitForAll怎麽用?Java MediaTracker.waitForAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.MediaTracker的用法示例。


在下文中一共展示了MediaTracker.waitForAll方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: convertToBufferedImage

import java.awt.MediaTracker; //導入方法依賴的package包/類
private BufferedImage convertToBufferedImage(Image image) throws IOException {
    if (image instanceof BufferedImage) {
        return (BufferedImage)image;

    } else {
        MediaTracker tracker = new MediaTracker(new Component(){}); // not sure if this is the right thing to do.
        tracker.addImage(image, 0);
        try {
            tracker.waitForAll();
        } catch (InterruptedException e) {
            throw new IOException(e.getMessage());
        }
        BufferedImage bufImage = new BufferedImage(
                image.getWidth(null),
                image.getHeight(null),
                BufferedImage.TYPE_INT_ARGB);

        Graphics g = bufImage.createGraphics();
        g.drawImage(image, 0, 0, null);
        return bufImage;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:23,代碼來源:RuntimeBuiltinLeafInfoImpl.java

示例2: fetchImage

import java.awt.MediaTracker; //導入方法依賴的package包/類
public Image fetchImage( URL imageLocation ) throws IOException {
    Image image = null;
    try {
        if ( imageLocation == null ) {
            throw new IOException( "Image resource not found: Null imagelocation URL" );
        }
        else {
            Toolkit toolkit = Toolkit.getDefaultToolkit();
            image = toolkit.createImage( imageLocation );
            MediaTracker tracker = new MediaTracker( this );
            tracker.addImage( image, 0 );
            tracker.waitForAll();
        }
    }
    catch ( InterruptedException e ) {
    }
    return image;
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:19,代碼來源:ImageLoader.java

示例3: getImage

import java.awt.MediaTracker; //導入方法依賴的package包/類
/**
 * Get Image from path provided
 *
 * @param url location of the image
 * @return the Image file
 */
public Image getImage(URL url) {
	try {
		MediaTracker tracker = new MediaTracker(this);
		
		Image image = super.getImage(url);

		// wait for image to load
		tracker.addImage(image, 0);
        tracker.waitForAll();

        // if no errors return image
        if (!tracker.isErrorAny()) {
        	return image;
        }
	} catch (Exception e) {
		/* */
	}
	
	return null;
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:27,代碼來源:AppletLoader.java

示例4: Splash

import java.awt.MediaTracker; //導入方法依賴的package包/類
public Splash(Frame parent, String imagefilename, boolean dialog)
   {
if (dialog)
    {
               m_window = new MyDialog(parent);
    }
else
    {
               m_window = new MyWindow(parent);
    }
javax.swing.ImageIcon icon = new javax.swing.ImageIcon(getClass().getResource(imagefilename));
m_splashImage = icon.getImage();
MediaTracker loader = new MediaTracker(m_window);
loader.addImage(m_splashImage, 0);
try { 
           loader.waitForAll(); 
} catch (Exception e) {}
   }
 
開發者ID:BisonSchweizAG,項目名稱:JSmooth,代碼行數:19,代碼來源:Splash.java

示例5: loadImage

import java.awt.MediaTracker; //導入方法依賴的package包/類
/**
 * Asks the user to select an image and then it loads it up into an Image
 * object and returns it to the calling class.
 *
 * @return java.awt.Image img the loaded image
 */
private static Image loadImage() {
  System.out.println("Select the map");
  final String mapName = new FileOpen("Select The Map", mapFolderLocation, ".gif", ".png").getPathString();
  if (mapName != null) {
    final Image img = Toolkit.getDefaultToolkit().createImage(mapName);
    final MediaTracker tracker = new MediaTracker(new Panel());
    tracker.addImage(img, 1);
    try {
      tracker.waitForAll();
      return img;
    } catch (final InterruptedException e) {
      Thread.currentThread().interrupt();
    }
  }
  return null;
}
 
開發者ID:triplea-game,項目名稱:triplea,代碼行數:23,代碼來源:ReliefImageBreaker.java

示例6: loadImage

import java.awt.MediaTracker; //導入方法依賴的package包/類
/**
 * java.awt.Image loadImage()
 * Asks the user to select an image and then it loads it up into an Image
 * object and returns it to the calling class.
 *
 * @return java.awt.Image img the loaded image
 */
private static Image loadImage() {
  System.out.println("Select the map");
  final String mapName = new FileOpen("Select The Map", mapFolderLocation, ".gif", ".png").getPathString();
  if (mapName != null) {
    final Image img = Toolkit.getDefaultToolkit().createImage(mapName);
    final MediaTracker tracker = new MediaTracker(new Panel());
    tracker.addImage(img, 1);
    try {
      tracker.waitForAll();
      return img;
    } catch (final InterruptedException e) {
      Thread.currentThread().interrupt();
    }
  }
  return null;
}
 
開發者ID:triplea-game,項目名稱:triplea,代碼行數:24,代碼來源:TileImageBreaker.java

示例7: CustomButton

import java.awt.MediaTracker; //導入方法依賴的package包/類
/**
 * Instantiates a new custom button.
 * 
 * @param toolTip
 *            the message that is displayed when hovering over the button
 *            with the mouse.
 * @param pathToDefaultImage
 *            the path to image representing the unpressed state of the
 *            button.
 * @param pathToPressedImage
 *            the path to image representing the pressed state of the
 *            button.
 * @param actionCommand
 *            the action command
 */
public CustomButton(String toolTip, String pathToDefaultImage, String pathToPressedImage, String actionCommand) {
	super();
	this.setToolTipText(toolTip);
	URL urlDefault = Main.class.getResource(pathToDefaultImage);
	URL urlPressed = Main.class.getResource(pathToPressedImage);

	this.imgDefault = null;
	this.imgPressed = null;
	Toolkit tk = Toolkit.getDefaultToolkit();
	try {
		MediaTracker m = new MediaTracker(this);
		this.imgDefault = tk.getImage(urlDefault);
		m.addImage(this.imgDefault, 0);
		this.imgPressed = tk.getImage(urlPressed);
		m.addImage(this.imgPressed, 0);
		m.waitForAll();
	} catch (Exception e) {
		e.printStackTrace();
	}

	// }
	this.setActionCommand(actionCommand);
	this.setLayout(new GridLayout(1, 1));
	this.setPreferredSize(new Dimension(imgDefault.getWidth(this), imgDefault.getHeight(this)));
}
 
開發者ID:enguerrand,項目名稱:xdat,代碼行數:41,代碼來源:CustomButton.java

示例8: makeBackgroundImage

import java.awt.MediaTracker; //導入方法依賴的package包/類
public static JLabel makeBackgroundImage(Graphwar graphwar, BufferedReader read) throws InterruptedException, IOException
{
	MediaTracker tracker = new MediaTracker(graphwar);
	
	Image image = ImageIO.read(graphwar.getClass().getResource(GraphUtil.nextLine(read)));	
	tracker.addImage(image, 0);		
	tracker.waitForAll();		
	
	int x = Integer.parseInt(GraphUtil.nextLine(read));
	int y = Integer.parseInt(GraphUtil.nextLine(read));
	
	JLabel imagePanel = new JLabel(new ImageIcon(image));
	imagePanel.setBounds(x, y, image.getWidth(null), image.getHeight(null));
	
	return imagePanel;
	
}
 
開發者ID:catabriga,項目名稱:graphwar,代碼行數:18,代碼來源:GraphUtil.java

示例9: makeButton

import java.awt.MediaTracker; //導入方法依賴的package包/類
public static GraphButton makeButton(Graphwar graphwar, BufferedReader read) throws InterruptedException, IOException
{
	MediaTracker tracker = new MediaTracker(graphwar);
	
	Image normal = ImageIO.read(graphwar.getClass().getResource(GraphUtil.nextLine(read)));
	tracker.addImage(normal, 0);
	Image over = ImageIO.read(graphwar.getClass().getResource(GraphUtil.nextLine(read)));
	tracker.addImage(over, 1);
	Image tempImg = ImageIO.read(graphwar.getClass().getResource(GraphUtil.nextLine(read)));
	tracker.addImage(tempImg, 2);
	tracker.waitForAll();
	
	
	BufferedImage mask = new BufferedImage(tempImg.getWidth(null), tempImg.getHeight(null), BufferedImage.TYPE_3BYTE_BGR);			
	mask.getGraphics().drawImage(tempImg, 0, 0, null);
	
	int x = Integer.parseInt(GraphUtil.nextLine(read));
	int y = Integer.parseInt(GraphUtil.nextLine(read));
			
	GraphButton graphButton = new GraphButton(normal, over, mask);
	graphButton.setBounds(x, y, normal.getWidth(null), normal.getWidth(null));
	
	return graphButton;
}
 
開發者ID:catabriga,項目名稱:graphwar,代碼行數:25,代碼來源:GraphUtil.java

示例10: startSplashScreen

import java.awt.MediaTracker; //導入方法依賴的package包/類
public static void startSplashScreen() {
        int width = 275, height = 148;
        Window win = new Window(new Frame());
        win.pack();
        BshCanvas can = new BshCanvas();
        can.setSize(width, height); // why is this necessary?
        Toolkit tk = Toolkit.getDefaultToolkit();
        Dimension dim = tk.getScreenSize();
        win.setBounds(dim.width / 2 - width / 2, dim.height / 2 - height / 2, width, height);
        win.add("Center", can);
        Image img = tk.getImage(Interpreter.class.getResource("/bsh/util/lib/splash.gif"));
        MediaTracker mt = new MediaTracker(can);
        mt.addImage(img, 0);
        try {
                mt.waitForAll();
        } catch (Exception e) {
        }
        Graphics gr = can.getBufferedGraphics();
        gr.drawImage(img, 0, 0, can);
        win.setVisible(true);
        win.toFront();
        splashScreen = win;
}
 
開發者ID:sing-group,項目名稱:aibench-project,代碼行數:24,代碼來源:Util.java

示例11: startSplashScreen

import java.awt.MediaTracker; //導入方法依賴的package包/類
public static void startSplashScreen()
    {
        Image img = getIcon("beast/app/draw/icons/beauti.png").getImage();
        int width=2 * img.getWidth(null), height=img.getHeight(null);
        Window win=new Window( new Frame() );
        win.pack();
        can = new Canvas();
        can.setSize( width, height ); // why is this necessary?
        Toolkit tk=Toolkit.getDefaultToolkit();
        Dimension dim=tk.getScreenSize();
        win.setBounds(
                dim.width/2-width/2, dim.height/2-height/2, width, height );
        win.add("Center", can);
//        Image img=tk.getImage(
//                Utils.class.getResource("beast.png") ); //what
        MediaTracker mt=new MediaTracker(can);
        mt.addImage(img,0);
        try { mt.waitForAll(); } catch ( Exception e ) { }
        Graphics gr=can.getBufferedGraphics();
        gr.drawImage(img, width / 4, 0, can);
        win.setVisible(true);
        win.toFront();
        splashScreen = win;
    }
 
開發者ID:CompEvol,項目名稱:beast2,代碼行數:25,代碼來源:Utils6.java

示例12: DirectSprite

import java.awt.MediaTracker; //導入方法依賴的package包/類
public DirectSprite(byte[] data, Component component) {
	try {
		Image image = Toolkit.getDefaultToolkit().createImage(data);
		MediaTracker mediaTracker = new MediaTracker(component);
		mediaTracker.addImage(image, 0);
		mediaTracker.waitForAll();
		width = image.getWidth(component);
		height = image.getHeight(component);
		resizeWidth = width;
		resizeHeight = height;
		horizontalOffset = 0;
		verticalOffset = 0;
		raster = new int[width * height];
		PixelGrabber grabber = new PixelGrabber(image, 0, 0, width, height, raster, 0, width);
		grabber.grabPixels();
	} catch (Exception ex) {
		System.out.println("Error converting jpg");
	}
}
 
開發者ID:atomicint,項目名稱:aj8,代碼行數:20,代碼來源:DirectSprite.java

示例13: decodeImage

import java.awt.MediaTracker; //導入方法依賴的package包/類
private void decodeImage(String name) throws InterruptedException {
	final Image im = createImage(name);
	final BufferedImage bim = new BufferedImage(EXP_WIDTH, EXP_HEIGHT,
			BufferedImage.TYPE_INT_RGB);
	final Frame f = new Frame();
	final MediaTracker t = new MediaTracker(f);

	t.addImage(im, 0);
	t.waitForAll();

	assertEquals(EXP_WIDTH, im.getWidth(null));
	assertEquals(EXP_HEIGHT, im.getHeight(null));

	bim.getGraphics().drawImage(im, 0, 0, null);
	int rgbVal = bim.getRGB(0, 0);
	assertEquals(0xFFFFFFFF, rgbVal);
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:18,代碼來源:BufferedImageTest.java

示例14: prepareImages

import java.awt.MediaTracker; //導入方法依賴的package包/類
public void prepareImages() {
    if (prepared) {
        return;
    }

    MediaTracker mt = new MediaTracker(this);
    for (int i = 0; i < images.length; i++) {
        mt.addImage(images[i], i);
    }
    try {
        mt.waitForAll();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    for (int i = 0; i < images.length; i++) {
        mt.removeImage(images[i], i);
    }

    if (params.scaleFactor != 1) {
        // TODO: scale if needed
        logger.unimplemented("image_scaling");
    }

    prepared = true;
}
 
開發者ID:ShiftMediaProject,項目名稱:libbluray,代碼行數:26,代碼來源:ImageFrameAccurateAnimation.java

示例15: getInstance

import java.awt.MediaTracker; //導入方法依賴的package包/類
public static ImagePainter getInstance(Component component, String name)
/*    */   {
/* 20 */     Toolkit toolkit = component.getToolkit();
/* 21 */     if (toolkit == null) throw new NullPointerException();
/* 22 */     if (toolkit != currentToolkit) cache = new HashMap(5);
/* 23 */     Object cached = cache.get(name);
/* 24 */     if (cached != null) return ((ImagePainter)cached);
/*    */ 
/* 26 */     URL url = ImagePainter.class.getResource(name);
/* 27 */     if (url == null) return new ImagePainter(null);
/* 28 */     Image img = toolkit.createImage(url);
/* 29 */     ImagePainter newPainter = new ImagePainter(img);
/* 30 */     MediaTracker mt = new MediaTracker(component);
/* 31 */     mt.addImage(img, 0);
/*    */     try {
/* 33 */       mt.waitForAll();
/*    */     }
/*    */     catch (InterruptedException e) {
/* 36 */       e.printStackTrace();
/*    */     }
/* 38 */     cache.put(name, newPainter);
/* 39 */     return newPainter;
/*    */   }
 
開發者ID:IMAGINARY,項目名稱:morenaments-euc,代碼行數:24,代碼來源:ImagePainter.java


注:本文中的java.awt.MediaTracker.waitForAll方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。