Monday, February 26, 2018

Java Swing program : A button with Icon

 import javax.swing.*;     
    public class ButtonWithIcon{   
    ButtonWithIcon(){   
    JFrame f=new JFrame("ButtonWithIcon");           
    JButton b=new JButton(new ImageIcon("D:\\JavaSwing\\lcd.png"));   
    b.setBounds(50,100,230, 130);   
    f.add(b);   
    f.setSize(400,400);   
    f.setLayout(null);   
    f.setVisible(true);   
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);   
        }        
    public static void main(String[] args) {   
        new ButtonWithIcon();   
    }   
    }   
Output

Thanks
Happy programming!

No comments:

Post a Comment

How can I run a C++ program directly from Windows?

How-can-I-run-a-C-program-directly-from-Windows