Perform Action Event On Button In Hindi #6

1,190 views · Published 31 October 2017 · 19:10 · Indexed 8 November 2026

Channel: AndroJavaTech4U · 2017 · Science & Technology

Watch on YouTube

Here we learn the  How to Performed Action Event On Button using same class Listener In Hindi By Surya Sir

Download  my you tube channel  Android application from here-
https://www.dropbox.com/s/stoehcarylm...

How to Create An U IUser Interface Using AWT In Java #1 URL
https://www.youtube.com/watch?v=n9NF1...

Event Handling Basic Url-

https://www.youtube.com/watch?v=DCurno8f-LA

path seting-
https://www.youtube.com/watch?v=k2gCo...

java doc-
https://www.youtube.com/watch?v=NLfXd...

Connect on Socials:-
Facebook:- https://www.facebook.com/AndroJavaTec...
Twitter:- https://twitter.com/AndroJavaTech4U
Google Plus:- https://plus.google.com/u/0/+AndroJav...
LinkedIn:- https://www.linkedin.com/in/androjava...

Program:-
import java.awt.*;
import java.awt.event.*;

class GuiApp extends Frame  implements ActionListener
{
//Frame f;
Label l,l1,l2;
TextField tf,tf1,tf2;
Button b,b1;
GuiApp(String title)
{
super(title);
 //f=new Frame("GuiApp");
this.setVisible(true);
 setSize(260,200);
  setResizable(false);
  setBackground(Color.yellow);
  setLocation(400,100);
System.out.println(this.getLocation());
l=new Label("Eneter First No");
l1=new Label("Eneter Second No");
l2=new Label("Result:-");
tf=new TextField(10);
tf1=new TextField(10);
tf2=new TextField(10);
b=new Button("Add");
b1=new Button("Sub");
b1.setForeground(Color.red); 
b.setForeground(Color.red); 

b.addActionListener(this); 
b1.addActionListener(this); 


 FlowLayout fl=new FlowLayout();

//FlowLayout fl=new FlowLayout(FlowLayout.RIGHT);
//FlowLayout fl=new FlowLayout(20,20,FlowLayout.RIGHT);
//GridLayout fl=new GridLayout(3,3);
//BorderLayout fl=new BorderLayout();
tf.setBackground(Color.pink);
tf1.setBackground(Color.pink);
tf2.setBackground(Color.pink);


this.setLayout(fl);

/*
l.setBackground(Color.pink);
l.setBounds(100,100,90,30);
tf.setBackground(Color.green);
tf.setBounds(200,100,90,30);

l1.setBackground(Color.pink);
l1.setBounds(100,150,120,30);
tf1.setBackground(Color.green);
tf1.setBounds(220,150,90,30);


l2.setBackground(Color.red);

*/
/*
Panel p=new Panel();
p.add(l);
p.add(tf);
p.setBackground(Color.pink);
f.add(p,BorderLayout.EAST);

Panel p1=new Panel();
p1.add(l1);
p1.add(tf1);
p1.setBackground(Color.orange);
f.add(p1,BorderLayout.WEST);

Panel p2=new Panel();
p2.add(l2);
p2.add(tf2);
p2.setBackground(Color.green);
f.add(p2,BorderLayout.NORTH);

Panel p3=new Panel();
p3.add(b);
p3.add(b1);
p3.setBackground(Color.orange);
f.add(p3,BorderLayout.SOUTH);
*/

/*
f.add(l,BorderLayout.EAST);
f.add(tf,BorderLayout.WEST);
f.add(l1,BorderLayout.NORTH);
f.add(tf1,BorderLayout.SOUTH);
f.add(l2,BorderLayout.CENTER);
f.add(tf2);
f.add(b);
f.add(b1);
 */

Panel p1=new Panel();
p1.add(l);
p1.add(tf);
p1.setBackground(Color.green);
 this.add(p1);

Panel p2=new Panel();
p2.add(l1);
p2.add(tf1);
p2.setBackground(Color.green);
 this.add(p2);

Panel p3=new Panel();
p3.add(l2);
p3.add(tf2);
p3.add(b);
p3.add(b1);

p3.setBackground(Color.green);
 this.add(p3);

 }

public static void main(String ss[])
{
GuiApp g=new GuiApp("GuiApp");
}

public void actionPerformed(ActionEvent e)
{
String n1=tf.getText();
String n2=tf1.getText();
if(n1.equals("") || n2.equals(""))
{
javax.swing.JOptionPane.showMessageDialog(null,"Plz Fill All the 

Fielnds");
}
else
{
double d=Double.parseDouble(n1);
double d1=Double.parseDouble(n2);
double r=0.0;

// Object obj=e.getSource();
 String obj=e.getActionCommand();
//if(obj==b)
if(obj.equals("Add"))
{

r=d+d1;
//tf2.setText(String.valueOf(r));
  tf2.setText("Sum="+r);

//System.out.println(obj);//
//System.out.println("hello");
}
else
{ 
//System.out.println("hi");
  r=d-d1;
//tf2.setText(String.valueOf(r));
tf2.setText("Sub="+r);
}

}}

}

More from this channel