CODING:
import javax.swing.*;import java.awt.*;
import java.awt.event.*;
class tab extends JFrame
implements ActionListener
{
JButton jb,jb1,jb2;
JTextField jtf;
tab()
{
super();
setTitle("IMAGE ICON EXAMPLE");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
ImageIcon pakistan = new ImageIcon("pk.png");
JButton jb = new JButton(pakistan);
jb.setActionCommand("Pakistan");
jb.addActionListener(this);
ImageIcon ame = new ImageIcon("am.png");
JButton jb1 = new JButton(ame);
jb1.setActionCommand("America");
jb1.addActionListener(this);
ImageIcon jap = new ImageIcon("japan.png");
JButton jb2 = new JButton(jap);
jb2.setActionCommand("JAPAN");
jb2.addActionListener(this);
jtf=new JTextField(15);
FlowLayout f=new FlowLayout();
setLayout(f);
add(jb);
add(jb1);
add(jb2);
add(jtf);
setSize(250, 300);
setVisible(true);
}
public void actionPerformed(ActionEvent ae){
jtf.setText(ae.getActionCommand());
}
}
class butt
{
public static void main(String args[])
{
tab x= new tab();
}
}
No comments:
Post a Comment