天天看點

在java中畫背景圖檔_在java中怎樣添加背景圖檔

展開全部

// 不加包,圖檔跟類檔案在一個目錄,指令行下編譯執62616964757a686964616fe4b893e5b19e31333262383634行就行了

// 如果建工程,圖檔放到工程根目錄

import java.awt.Container;

import java.awt.FlowLayout;

import javax.swing.ImageIcon;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

public class Student extends JFrame {

public Student() {

init();

}

private void init() {

final Container c = getContentPane();

final JLabel imgLabel = new JLabel();

ImageIcon img = new ImageIcon(System.getProperty("user.dir") + "\\a.png");

imgLabel.setIcon(img);

imgLabel.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());

((JPanel)getContentPane()).setOpaque(false);

getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));

setLayout(new FlowLayout());

setSize(500, 500);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public static void main(String[] args) {

new Student().setVisible(true);

}

}

在java中畫背景圖檔_在java中怎樣添加背景圖檔