public class Test extends JFrame {
public static void main(String[] args) {
new Test();
}
public Test() {
JPanel panel = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Image image = new ImageIcon("picture.png").getImage();
int width = Test.getFrames()[0].getWidth();
int heigh = Test.getFrames()[0].getHeight();
g.drawImage(image, 0, 0, width, heigh, null);
}
};
add(panel);
setBounds(500, 100, 480, 320);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
java.swing api有详细解释