source file name:  ButtonTextPanelDemo.java

 import java.awt.*; 

import java.awt.event.*;  

import javax.swing.*;   

import javax.swing.text.*; 

class ButtonTextPanelDemo extends JFrame implements ActionListener

{

public ButtonTextPanelDemo()

{

    setLayout(null);  

JButton bt1=new JButton("RashtraGeet");  

JButton bt2=new JButton("Pldge");  

JButton bt3=new JButton("RashtraSong");  

    bt1.setBounds(20,50, 150,30);  

    bt2.setBounds(160,50, 100,30);  

    bt3.setBounds(270,50, 150,30);  

    

add(bt1);add(bt2);add(bt3);

    bt1.addActionListener(this);

    bt2.addActionListener(this);

    bt3.addActionListener(this);

}

  public void actionPerformed(ActionEvent ae) 

{  

String s=ae.getActionCommand();

String str="";

try

{

if(s.equals("RashtraGeet"))

str="janganman.jpg";


if(s.equals("Pldge"))

str="pledge.jpg";


if(s.equals("RashtraSong"))

str="vande.jpg";


 open(str);        

   

}

catch(Exception e){}

  }  

 public void open(String img) throws BadLocationException

{

JWindow w=new JWindow();

JTextPane tp = new JTextPane();

StyledDocument doc2 = (StyledDocument) tp.getDocument();

      Style style2 = doc2.addStyle("StyleName", null);

      StyleConstants.setIcon(style2, new ImageIcon(img));

      doc2.insertString(doc2.getLength(), "invisible text", style2);

      JScrollPane sp = new JScrollPane(tp);

        w.add(sp, BorderLayout.CENTER);

w.setLocation(510, 10);

w.setSize(850, 600);

w.setVisible(true);

}


public static void main(String[] args)

 {  

ButtonTextPanelDemo f=new ButtonTextPanelDemo();


f.setTitle(" Swing Label & Button program");  

    f.setSize(500,200);  

    f.setVisible(true);   

}  

}  

output: