beingtopper.jkp@gmail.com
+91-8700702530
Free Demo

Being Topper

  • About Us
  • Knowledge Base
  • Modules
  • Branches
    • Ajmer
    • Tilak Nagar
    • Noida
    • Chandigarh
    • Mumbai
  • Contact Us

Being Topper

  • About Us
  • Knowledge Base
  • Modules
  • Branches
    • Ajmer
    • Tilak Nagar
    • Noida
    • Chandigarh
    • Mumbai
  • Contact Us
  • About Us
  • Knowledge Base
  • Modules
  • Branches
    • Ajmer
    • Tilak Nagar
    • Noida
    • Chandigarh
    • Mumbai
  • Contact Us

Being Topper

  • About Us
  • Knowledge Base
  • Modules
  • Branches
    • Ajmer
    • Tilak Nagar
    • Noida
    • Chandigarh
    • Mumbai
  • Contact Us
B.tech notesBCA NOTESEvent HandlingInformation technologyJava Programs

Java program for event Handelling

Being Topper 17/03/2014 0 Comments

Java program for event Handelling

import java.awt.*;
import java.awt.event.*;
class EventTest implements ActionListener
{Frame fr;
Button b1,b2,b3,b4;
TextField tf1,tf2,tf3;
Label lb1,lb2,lb3;

EventTest( )
{ fr = new Frame("myframe" );
fr.setLayout(null);
b1= new Button ("Add") ;
b2= new Button ("Sub") ;
b3= new Button ("Mul") ;
b4= new Button ("Div") ;
tf1 = new TextField() ;
tf2 = new TextField() ;
tf3= new TextField() ;
lb1 = new Label("no1") ;
lb2 = new Label("no2") ;
lb3 = new Label("res") ;
tf1.setBounds( 50,50,100,50) ;
tf2.setBounds( 50,120,100,50) ;
tf3.setBounds( 50,190,100,50) ;
lb1.setBounds(10,50,35,50);
lb2.setBounds(10,120,35,50);
lb3.setBounds(10,190,35,50);
b1.setBounds( 30,260,35,50);
b2.setBounds( 85,260,35,50);
b3.setBounds( 140,260,35,50);
b4.setBounds( 195,260,35,50);
fr.add( tf1) ;
fr.add( tf2) ;
fr.add( tf3) ;
fr.add( lb1) ;
fr.add( lb2) ;
fr.add( lb3) ;
fr.add( b1) ;
fr.add( b2) ;
fr.add( b3) ;
fr.add( b4) ;
b1.addActionListener( this );
b2.addActionListener( this );
b3.addActionListener( this );
b4.addActionListener( this );

fr.setSize(600,700);
fr.setVisible(true);
}
public void actionPerformed (ActionEvent e )
{
if ( e.getSource() == b1 )
{
String str1 = tf1.getText() ;
String str2 = tf2.getText() ;
int s1 = Integer.parseInt(str1) ;
int s2 = Integer.parseInt(str2) ;
int result = (s1+s2) ;
String str3 =" " + result ;
tf3.setText ( str3) ;
}

if ( e.getSource() == b2 )
{
String str1 = tf1.getText() ;
String str2 = tf2.getText() ;
int s1 = Integer.parseInt(str1) ;
int s2 = Integer.parseInt(str2) ;
int result = s1-s2 ;
String str3 =" " + result ;
tf3.setText ( str3) ;
}
if ( e.getSource() == b3 )
{
String str1 = tf1.getText() ;
String str2 = tf2.getText() ;
int s1 = Integer.parseInt(str1) ;
int s2 = Integer.parseInt(str2) ;
int result = s1*s2 ;
String str3 =" " + result ;
tf3.setText ( str3) ;
}

if ( e.getSource() == b4 )
{
String str1 = tf1.getText() ;
String str2 = tf2.getText() ;
int s1 = Integer.parseInt(str1) ;
int s2 = Integer.parseInt(str2) ;
int result = (s1/s2) ;
String str3 =" " + result ;
tf3.setText ( str3) ;
}
}

public static void main (String s[] )
{
new EventTest();
}

}

java programs
AboutBeing Topper
In Socials:
PrevJava Program for working Pacman game18/02/2014
java program for counting vowels , consonants , digits and whitespaces ...17/03/2014Next

Related Posts

AppletB.tech notesBCA NOTESInformation technologyJava ProgramsPrograms/Algorithm

Java Program for working Pacman game

Java Program/source code for working Pacman Game. This program is primarily based on...

Being Topper 18/02/2014
Basic ProgramsJava Programs

program on break apart a number in java

program on break apart a number in java (more…)

Being Topper 18/02/2014
Categories
Recent Posts
  • Best Email Marketing Software and Services
  • How to Apply Adsense on YouTube
  • Complete Guide to Writing a Newsletter !
  • Benefits of Creating Email List for small Businesses | Digital Marketing
  • Create Account or Get Email Alerts When New Employees Join a Company

Copyright © 2021 Being Topper ® . All Rights Reserved