一个有关背景(透明)颜色设置的问题?
import java.applet.*;
代码如下:
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
class YY1 extends Applet
{int i=0;
public void paint(Graphics g)
{
g.setFont(new Font("",1,30));
switch (i){
case 0:g.drawString("没",0,30);
try{Thread.sleep(500);}catch(InterruptedException e){}
i++; repaint();
break;
case 1:g.drawString("没事",0,30);
try{Thread.sleep(500);}catch(InterruptedException e){}
i++;
repaint();
break;
case 2:g.drawString("没事的",0,30);
try{Thread.sleep(500);}catch(InterruptedException e){}
i++;
repaint();
break;
case 3:g.drawString("没事的时",0,30);
try{Thread.sleep(500);}catch(InterruptedException e){}
i++;
repaint();
break;
case 4:g.drawString("没事的时候",0,30);
try{Thread.sleep(500);}catch(InterruptedException e){}
i++;
repaint();
break; case 5:g.drawString("没事的时候写",0,30);
try{Thread.sleep(500);}catch(InterruptedException e){}
i++;
repaint();
break; case 6:g.drawString("没事的时候写写",0,30);
try{Thread.sleep(500);}catch(InterruptedException e){}
i++; repaint();
break; case 7:g.drawString("没事的时候写写代",0,30);
try{Thread.sleep(500);}catch(InterruptedException e){}
i++; repaint();
break;
case 8:g.drawString("没事的时候写写代码",0,30);
try{Thread.sleep(500);}catch(InterruptedException e){}
i++;
repaint();
break;
case 9:g.drawString("没事的时候写写代码……",0,30);
try{Thread.sleep(500);}catch(InterruptedException e){}
i=0;
repaint();
break;
}
}
}
class YY implements Runnable{
YY(){
YY1 y = new YY1();
Window w = new Window(null);
w.setLayout(null);
w.add(y);
y.setBounds(0,0,600,40);
y.setBackground(new Color(0,255,0,0));
w.setSize(400,400);
w.setVisible(true);
w.setBounds(300,50,600,40);
w.setBackground(new Color(0,0,255,0));
w.toBack();
}
public void run()
{
new YY1();
}
public static void main(String [] arge)
{
Thread r = new Thread(new YY());
r.start();
}
}
本来照我的想法,这东东在桌面上显示出来的,应该就只有那几个字,不应该会有背景颜色的,可是无论我怎么改,总会有背景颜色,各位大吓们,能否帮小弟解决这个问题,谢谢!!!
------解决方案--------------------
用jdk1.6吧,有个AWTUtilities类,里面有个setOpacy()方法,可以设置透明窗口。1.6以下的版本不知道能不能设。