Welcome to Abdul Malik Ikhsan's Blog

ImageIcon pada Swing

Posted in Tutorial Java by samsonasik on August 11, 2007

Kita siapkan dulu, buku.png dan button.png
————–

Code:
import javax.swing.*;
import java.awt.*;public class ContohImageIcon extends JFrame{
public static void main(String args[]){
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame f=new JFrame(“Contoh Image Icon”);
f.setBounds(100,100,400,200);ImageIcon icon=new ImageIcon(“buku.png”);
f.setIconImage(icon.getImage());
f.setResizable(false);ImageIcon icon2=new ImageIcon(“button.png”);
JButton button=new JButton(“Tombol Bergambar”,icon2);
button.setBounds(65,50,270,50);
f.getContentPane().add(button);
f.getContentPane().setLayout(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}


icon.jpg

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: