Wednesday, January 22, 2014

Event Handling (Example 3)

import java.awt.*;
import java.awt.event.*;
class kali implements ActionListener
{
Frame f;
Button b1,b2,b3,b4,b5,b6,b7,b8,b9;
TextField t;
kali(String s)
{
f=new Frame(s);
t=new TextField();
t.setBounds(100,80,260,30);
f.add(t);
b1=new Button("MaHi");
b2=new Button("Bips");
b3=new Button("Swami");
b4=new Button("Ashu");
b5=new Button("Jigs");
b6=new Button("Dhanno");
b7=new Button("Anil");
b8=new Button("Piyu");
b9=new Button("Bhavu");

b1.setBounds(100,140,60,40);
b2.setBounds(100,220,60,40);
b3.setBounds(100,300,60,40);
b4.setBounds(200,140,60,40);
b5.setBounds(200,220,60,40);
b6.setBounds(200,300,60,40);
b7.setBounds(300,140,60,40);
b8.setBounds(300,220,60,40);
b9.setBounds(300,300,60,40);

b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
f.add(b1);
f.add(b2);
f.add(b3);
f.add(b4);
f.add(b5);
f.add(b6);
f.add(b7);
f.add(b8);
f.add(b9);

f.setLayout(null);
f.setSize(500,420);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
t.setText("Good Wise and Kind Person");
if(e.getSource()==b2)
t.setText("BD ki Deepika");
if(e.getSource()==b3)
t.setText("Khodamba Ka vir Bikshuk");
if(e.getSource()==b4)
t.setText("Appu ka Big Brother and Appa Love");
if(e.getSource()==b5)
t.setText("Ghaghra no big Dealer");
if(e.getSource()==b6)
t.setText("IANT ni Ramayan no Hero");
if(e.getSource()==b7)
t.setText("Khovayeli Duniya no king");
if(e.getSource()==b8)
t.setText("BakBak Leader");
if(e.getSource()==b9)
t.setText("Sagai pachi ni GulliMaru");
}
public static void main(String surat[])
{
new kali("Kali");
}
}

Output:

No comments:

Post a Comment