Saturday, 26 May 2012

JAVA GUI application to find sum of two numbers


import java.awt.*;
import java.awt.event.*;

import javax.swing.*;


public class Ass140 extends JFrame implements ActionListener
{
JLabel l1,l2,l3;
JButton b1;
JTextField t1,t2,t3;

Ass140()
{
l1=new JLabel("INPUT 1");
l2=new JLabel("INPUT 2");
l3=new JLabel("OUTPUT");
b1=new JButton("BUTTON 1");

t1=new JTextField(10);
t2=new JTextField(10);
t3=new JTextField(10);

add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(b1);

b1.addActionListener(this);

setSize(200,200);
setLayout(new FlowLayout());
setTitle("Assignment 139");
}

public void actionPerformed(ActionEvent ae)
{
float a,b,c;
if(ae.getSource()==b1)
{
a=Float.parseFloat(t1.getText());
b=Float.parseFloat(t2.getText());
c=a+b;
t3.setText(String.valueOf(c));

}


}

public static void main(String args[])
{
Ass140 a=new Ass140();
a.setVisible(true);
a.setLocation(200,200);

}

}

15 comments:

  1. Thank you so much for posting this example

    ReplyDelete
  2. Thank you so much for posting this example

    ReplyDelete
  3. write a program takes two numbers from the user and display their addition using GUI

    i need the answer of this question right now

    ReplyDelete
  4. Nice Blog Sir...

    related POst :- how to easily start programming in java??

    https://coding-worm.blogspot.in/2017/08/v-behaviorurldefaultvmlo.html

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. how to add exit button and exit???

    ReplyDelete
  7. Really great post, I simply unearthed your site and needed to say that I have truly appreciated perusing your blog entries.
    python Training institute in Pune
    python Training institute in Chennai
    python Training institute in Bangalore

    ReplyDelete
  8. Very reliable to we the beginners of the programmer. Easy to understand Sir.
    Keep posting new programs Sir

    ReplyDelete
  9. I am highly overwhelmed to read this perfect piece of writing. It has really enthused me to read more on this topic.
    Data Science training in Mumbai
    Data Science course in Mumbai
    SAP training in Mumbai

    ReplyDelete
  10. I feel a lot more people need to read this, very good info! .
    data scientist training and placement



    ReplyDelete
  11. They're produced by the very best degree developers who will be distinguished for your polo dress creation. You'll find Ron Lauren inside an exclusive array which includes particular classes for men, women.
    data analytics courses in hyderabad

    ReplyDelete