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);

}

}

7 comments:

  1. Thank you so much for posting this example

    ReplyDelete
  2. Thank you so much for posting this example

    ReplyDelete
  3. I have read your blog its very attractive and impressive. I like it your blog.

    Java Online Training Java EE Online Training Java EE Online Training Java 8 online training Core Java 8 online training

    Java Online Training from India Java Online Training from India Core Java Training Online Core Java Training Online Java Training InstitutesJava Training Institutes

    ReplyDelete
  4. 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
  5. Nice Blog Sir...

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

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

    ReplyDelete