上传者: edyang123
|
上传时间: 2021-10-29 10:42:22
|
文件大小: 118KB
|
文件类型: -
mport java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class test {
ImageIcon imageIcon =new ImageIcon("透明旋转枫.gif");//images这个文件
ImageIcon imagebutton=new ImageIcon("button.png");
JLabel j2=new JLabel();
public test(){
final JFrame f= new JFrame();
f.setBounds(0,00,400,300);
f.setDefaultCloseOperation(3);
f.setUndecorated(true);
com.sun.awt.AWTUtilities.setWindowOpaque(f,false);//设置窗体透明
JPanel p=new JPanel(){
public void paintComponent(Graphics g){//重写paintComponent
super.paintComponent(g);//继承的绘制组件方法
Graphics2D gg=(Graphics2D)g;
if(imageIcon !=null){//绘制背景
gg.drawImage(imageIcon.getImage(),0,0,f.getWidth(),f.getHeight(),f);
}
}
};
p.setLayout(null);//空布局 任意摆放 与下面的b1.setBounds(280,80,60,25);呼应
JButton b1=new JButton("exit",imagebutton);
b1.addActionListener(new ActionListener(){
public void actionPerformed (ActionEvent e){
System.exit(0);
}
});