本文整理汇总了Java中java.awt.MediaTracker类的典型用法代码示例。如果您正苦于以下问题:Java MediaTracker类的具体用法?Java MediaTracker怎么用?Java MediaTracker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MediaTracker类属于java.awt包,在下文中一共展示了MediaTracker类的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;
}
}
示例2: testToolkitMultiResolutionImageLoad
import java.awt.MediaTracker; //导入依赖的package包/类
static void testToolkitMultiResolutionImageLoad(Image image) throws Exception {
MediaTracker tracker = new MediaTracker(new JPanel());
tracker.addImage(image, 0);
tracker.waitForID(0);
if (tracker.isErrorAny()) {
throw new RuntimeException("Error during image loading");
}
tracker.removeImage(image, 0);
testImageLoaded(image);
int w = image.getWidth(null);
int h = image.getHeight(null);
Image resolutionVariant = ((MultiResolutionImage) image)
.getResolutionVariant(2 * w, 2 * h);
if (image == resolutionVariant) {
throw new RuntimeException("Resolution variant is not loaded");
}
testImageLoaded(resolutionVariant);
}
示例3: testToolkitMultiResolutionImageLoad
import java.awt.MediaTracker; //导入依赖的package包/类
static void testToolkitMultiResolutionImageLoad(Image image)
throws Exception {
MediaTracker tracker = new MediaTracker(new JPanel());
tracker.addImage(image, 0);
tracker.waitForID(0);
if (tracker.isErrorAny()) {
throw new RuntimeException("Error during image loading");
}
tracker.removeImage(image, 0);
testImageLoaded(image);
int w = image.getWidth(null);
int h = image.getHeight(null);
Image resolutionVariant = ((MultiResolutionImage) image)
.getResolutionVariant(2 * w, 2 * h);
if (image == resolutionVariant) {
throw new RuntimeException("Resolution variant is not loaded");
}
testImageLoaded(resolutionVariant);
}
示例4: loadimages
import java.awt.MediaTracker; //导入依赖的package包/类
static private void loadimages() {
final Toolkit toolkit = Toolkit.getDefaultToolkit();
final MediaTracker mediatracker = new MediaTracker(app);
dnload += 8;
try {
for (int i = 0; i < idts.length; i++) {
idts[i].cons.accept(Files.readAllBytes(new File(Madness.fpath + "data/images/" + idts[i].fileName).toPath()), mediatracker, toolkit);
}
dnload += 2;
} catch (final Exception exception) {
System.err.println("Error Loading Images: " + exception);
}
System.gc();
}
示例5: 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;
}
示例6: 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;
}
示例7: getFileAsImage
import java.awt.MediaTracker; //导入依赖的package包/类
public Image getFileAsImage(String pathName, String[] retFileNameOrError) {
if (!haveDisplay) {
retFileNameOrError[0] = "no display";
return null;
}
Image image = fileManager.getFileAsImage(pathName, retFileNameOrError);
if (image == null)
return null;
MediaTracker tracker = new MediaTracker(display);
tracker.addImage(image, 0);
try {
tracker.waitForID(0);
} catch (InterruptedException e) {
// Got to do something?
}
return image;
}
示例8: run
import java.awt.MediaTracker; //导入依赖的package包/类
/**
*
*/
public void run() throws JRException
{
long start = System.currentTimeMillis();
//Preparing parameters
Image image = Toolkit.getDefaultToolkit().createImage("dukesign.jpg");
MediaTracker traker = new MediaTracker(new Panel());
traker.addImage(image, 0);
try
{
traker.waitForID(0);
}
catch (Exception e)
{
e.printStackTrace();
}
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("ReportTitle", "The First Jasper Report Ever");
parameters.put("MaxOrderID", new Integer(10500));
parameters.put("SummaryImage", image);
JasperRunManager.runReportToPdfFile("build/reports/FirstJasper.jasper", parameters, getDemoHsqldbConnection());
System.err.println("PDF running time : " + (System.currentTimeMillis() - start));
}
示例9: 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) {}
}
示例10: DuplicateAudioDevice
import java.awt.MediaTracker; //导入依赖的package包/类
DuplicateAudioDevice() {
super("");
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttDuplicateAudioDevice"));
try {
URL url = ClassLoader.getSystemClassLoader().getResource (
"org/jsampler/view/classic/res/icons/Copy16.gif"
);
ImageIcon icon = new ImageIcon(url);
if(icon.getImageLoadStatus() == MediaTracker.COMPLETE)
putValue(Action.SMALL_ICON, icon);
} catch(Exception x) {
CC.getLogger().log(Level.INFO, HF.getErrorMessage(x), x);
}
setEnabled(false);
}
示例11: RemoveAudioDevice
import java.awt.MediaTracker; //导入依赖的package包/类
RemoveAudioDevice() {
super("");
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttRemoveAudioDevice"));
try {
URL url = ClassLoader.getSystemClassLoader().getResource (
"org/jsampler/view/classic/res/icons/Delete16.gif"
);
ImageIcon icon = new ImageIcon(url);
if(icon.getImageLoadStatus() == MediaTracker.COMPLETE)
putValue(Action.SMALL_ICON, icon);
} catch(Exception x) {
CC.getLogger().log(Level.INFO, HF.getErrorMessage(x), x);
}
setEnabled(false);
}
示例12: AudioDeviceProps
import java.awt.MediaTracker; //导入依赖的package包/类
AudioDeviceProps() {
super("");
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttAudioDeviceProps"));
try {
URL url = ClassLoader.getSystemClassLoader().getResource (
"org/jsampler/view/classic/res/icons/Properties16.gif"
);
ImageIcon icon = new ImageIcon(url);
if(icon.getImageLoadStatus() == MediaTracker.COMPLETE)
putValue(Action.SMALL_ICON, icon);
} catch(Exception x) {
CC.getLogger().log(Level.INFO, HF.getErrorMessage(x), x);
}
setEnabled(false);
}
示例13: setCommandContext
import java.awt.MediaTracker; //导入依赖的package包/类
public void setCommandContext(String verb, DataHandler dh)
throws IOException
{
// Read image into a byte array
InputStream in = dh.getInputStream();
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
byte[] buf = new byte[4096];
for (int len = in.read(buf); len != -1; len = in.read(buf))
bytes.write(buf, 0, len);
in.close();
// Create and prepare the image
Toolkit toolkit = getToolkit();
Image img = toolkit.createImage(bytes.toByteArray());
try
{
MediaTracker tracker = new MediaTracker(this);
tracker.addImage(img, 0);
tracker.waitForID(0);
}
catch (InterruptedException e)
{
}
toolkit.prepareImage(img, -1, -1, this);
}
示例14: init
import java.awt.MediaTracker; //导入依赖的package包/类
public void init() {
Button b = new Button("Start");
b.addActionListener(this);
setLayout(new BorderLayout());
add(b, BorderLayout.NORTH);
add(p = new Panel(), BorderLayout.CENTER);
p.setLayout(null);
String imgName = getParameter("imagefile");
if (imgName == null) imgName = "duke.gif";
img = getImage(getCodeBase(), imgName);
MediaTracker mt = new MediaTracker(this);
mt.addImage(img, 0);
try {
mt.waitForID(0);
} catch(InterruptedException e) {
throw new IllegalArgumentException(
"InterruptedException while loading image " + imgName);
}
if (mt.isErrorID(0)) {
throw new IllegalArgumentException(
"Couldn't load image " + imgName);
}
v = new Vector<Sprite>(); // multithreaded, use Vector
}
示例15: drawMap
import java.awt.MediaTracker; //导入依赖的package包/类
/**
* Creates a 2D map at a given center point.
* @param newCenter the new center location
*/
public void drawMap(Coordinates newCenter) {
if ((newCenter != null) && (!newCenter.equals(currentCenter))) {
mapImage = createMapImage(newCenter);
MediaTracker mt = new MediaTracker(displayArea);
mt.addImage(mapImage, 0);
try {
mt.waitForID(0);
}
catch (InterruptedException e) {
logger.log(Level.SEVERE,Msg.getString("CannedMarsMap.log.mediaTrackerInterrupted") + e); //$NON-NLS-1$
}
mapImageDone = true;
currentCenter = new Coordinates(newCenter);
}
}