62,614
社区成员
发帖
与我相关
我的任务
分享
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class KFrame extends JFrame
{
private ImageIcon background1; //背景
private JPanel jpanel1; //面板
KFrame()
{
this.setTitle("Frame");
this.setBackground();
//this.setUndecorated(true);
this.setVisible(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
//设置背景
private void setBackground()
{
//背景图片
background1 = new ImageIcon("Image\\Background\\background2.jpg");
JLabel label = new JLabel(background1);
//获得窗口内容的面板
jpanel1 = (JPanel)this.getContentPane();
//使面板透明化
jpanel1.setOpaque(true);
//加入背景
this.getLayeredPane().add( label,new Integer(Integer.MIN_VALUE) );
this.setBounds( 0,0,background1.getIconWidth(),background1.getIconHeight() );
}
public static void main( String[] args )
{
KFrame f = new KFrame();
}
}