Java/Image Audio Video

From Meshplex

Jump to: navigation, search
Image:Java_programming.jpg
Introduction to Java
Overview of Java
How to Setup Java on your PC
Java Data Types, Variables,and Arrays
Java Operators
Java Packages, Classes, and Interfaces
Java Program
Java Modifiers
Java Control Statements
Java Exception Handling
Java Object Oriented Programming
Java Wrappers
Java Strings
Java Math
Java Arrays
Java Random Numbers
Java Date and Time
Java Regular Expressions
Java Collections
Java Generics
Java Thread and Multithreading
Java IO and file Handling
Java Network Programming
Java RMI
Image, Audio, Video
Java GUI
Java Applets
Java Internationalization
JDBC
Java and XML

[edit] Images

One can display an image using java.awt.Image class. This class is part of AWT framework. Since this class is an abstract superclass of all image classes we cannot instantiate using this class. We need to obtain the instance of Image in a platform specific manner. Different platform handle image rendering in different way. Direct subclasses or implementation classes available on a platform are java.awt.image.BufferedImage and java.awt.image.VolatileImage. Further these classes have there own list of subclasses.


import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.net.URL;
 
public class ImageExample extends Applet {
 
  // image name;
  Image imageFileName;
 
  // The MediaTracker class is a utility class to 
  // track the status of a number of media objects
  // like Image in our case.
  MediaTracker mediaTracker;
 
  // The applet base URL. Required to load the
  // image from this location.
  URL baseURL;
 
  public void init() {
 
    mediaTracker = new MediaTracker(this); 
    // getDocumentbase method gets the applet location.
    // This will be helpful only when the image
    // file is saved in the same directory location
    // from where this applet will be loaded.
    try {
     baseURL = getDocumentBase();
    } catch(Exception e) {
      e.printStackTrace();
    }
 
    // only .gif and .jpg file are allowed to load.
    // save team.jpg in the directory location from
    // where you wish to execute this applet.
    imageFileName = getImage(baseURL, "team.jpg"); 
    mediaTracker.addImage(imageFileName, 1);
 
    // stop the applet execution by making the mediaTracker to wait
    // until the image is fully loaded.
    try {
      mediaTracker.waitForAll();
    }
    catch (InterruptedException e) {
    }
  }
 
  public void paint(Graphics g) {
    // draw the image on the screen 
    g.drawImage(imageFileName, 10, 10, this);  
 
  }
 
}


Audio
Java provides APIs to access and play audio clips. Playing an audio clips in applets is quite simple. Java
Video