//下面是一个关于设置颜色的透明度的例子(注意:需指定一个图片的路径)
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class Hyaline {
public static void main (String[] args) throws Exception {
JFrame f=new JFrame()
{
{
Tracker=new MediaTracker(this);
Tracker.addImage(Pic, 0);
Tracker.waitForID(0);
setSize(Pic.getWidth(this),Pic.getHeight(this));
setResizable(false);
new javax.swing.Timer(2500,new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
repaint();
}
}).start();
}
public void paint(Graphics g)
{
final int Num=10;
int w=200,h=150;
int maxx=Pic.getWidth(this)-w;
int maxy=Pic.getHeight(this)-h;
g.drawImage(Pic,0,0,null);
for(int i=0;i
{
g.setColor(new Color(R.nextInt(256),R.nextInt(256),R.nextInt(256),R.nextInt(256)));
g.fillOval(R.nextInt(maxx),R.nextInt(maxy),w,h);
}
}
};
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
//将PicPath的值指定为你的图片的路径
static String PicPath="p.jpg";
static Image Pic=Toolkit.getDefaultToolkit().getImage(PicPath);
static MediaTracker Tracker;
static Random R=new Random();
}