import java.awt.AlphaComposite;
import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.JFrame;
public class MainClass extends JFrame {
public static void main(String args[]) {
MainClass app = new MainClass();
}
public MainClass() {
super("Draw2D");
add("Center", new MyCanvas());
setSize(400, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
class MyCanvas extends Canvas {
public void paint(Graphics graphics) {
Graphics2D g = (Graphics2D) graphics;
float alpha = 0.5f;
AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha);
g.setComposite(composite);
Toolkit toolkit = Toolkit.getDefaultToolkit();
Image image0 = toolkit.getImage("image0.gif");
Image image1 = toolkit.getImage("image1.gif");
g.drawImage(image0, 200, 100, this);
g.drawImage(image1, 100, 150, this);
}
}
}