在下面的程序中添加可以在电脑中选择图片作为背景的语句(就是山水风景那块)importjava.awt.Container;importjavax.swing.ImageIcon;importjavax.swing.JFrame;importjavax.swing.JL...
在下面的程序中添加可以在电脑中选择图片作为背景的语句(就是山水风景那块)
import java.awt.Container;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Test extends JFrame {
public Test() {
setBak();
Container c = getContentPane();
MazeWindow jp = new MazeWindow();
jp.setOpaque(false);
c.add(jp);
setSize(540, 450);
setVisible(true);
}
public void setBak(){
((JPanel)this.getContentPane()).setOpaque(false);
ImageIcon img = new ImageIcon("山水风景.jpg");
JLabel background = new JLabel(img);this.getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));
background.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());
}
public static void main(String[] args) {
Test s = new Test();
s.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
展开