Welcome Message

MEMBACA IDE KREASI

Selamat datang di Blog Saya, Tempat berbagi ilmu pemrograman. Hayo siapa yang jago, di share dimari :)
twitter

Follow on Tweets

Kamis, 29 Desember 2011

Background Image in JDesktopPane

caranya menambahkan background image ke dalam JDesktopPane di NetBeans IDE ? Nah kalau bingung, sekarang buatlah sebuah project dahulu di NetBeans IDE kemudian buatlah 1 buah Java Class dengan nama JImageDesktopPane (Nama CLass bisa diganti ya) .berikut source codenta :



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jdesktoppanebackground;
 
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.JDesktopPane;
 
/**
 *
 * @author Martinus Ady H <mrt.itnewbies@gmail.com>
 */
public class JImageDesktopPane extends JDesktopPane {
 
    private Image image;
 
    public JImageDesktopPane() {
    }
 
    @Override
    protected void paintComponent(Graphics g) {
        try {
            image = new javax.swing.ImageIcon(getClass().getResource("netbeans6ns0.png")).getImage();
 
            if (g != null) {
                g.drawImage(image,
                        (this.getSize().width - image.getWidth(null)) / 2,
                        (this.getSize().height - image.getHeight(null)) / 2,
                        null);
            }
        } catch (NullPointerException npe) {
            System.out.println("Can't find images !!");
        }
    }
}