Advertisement
NB52053

Untitled

Aug 23rd, 2017
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. http://www.dreamincode.net/forums/topic/224851-adding-two-numbers/
  2.  
  3. import java.awt.*;
  4. import java.awt.event.*;
  5.  
  6. import javax.swing.*;
  7.  
  8.  
  9. public class Ass140 extends JFrame implements ActionListener
  10. {
  11.  JLabel l1,l2,l3;
  12.  JButton b1;
  13.  JTextField t1,t2,t3;
  14.  
  15.  Ass140()
  16.  {
  17.   l1=new JLabel("INPUT 1");
  18.   l2=new JLabel("INPUT 2");
  19.   l3=new JLabel("OUTPUT");
  20.   b1=new JButton("BUTTON 1");
  21.  
  22.   t1=new JTextField(10);
  23.   t2=new JTextField(10);
  24.   t3=new JTextField(10);
  25.  
  26.   add(l1);
  27.   add(t1);
  28.   add(l2);
  29.   add(t2);
  30.   add(l3);
  31.   add(t3);
  32.   add(b1);
  33.  
  34.   b1.addActionListener(this);
  35.  
  36.   setSize(200,200);
  37.   setLayout(new FlowLayout());
  38.   setTitle("Assignment 139");
  39.  }
  40.  
  41.  public void actionPerformed(ActionEvent ae)
  42.  {
  43.   float a,b,c;
  44.   if(ae.getSource()==b1)
  45.   {
  46.    a=Float.parseFloat(t1.getText());
  47.    b=Float.parseFloat(t2.getText());
  48.    c=a+b;
  49.    t3.setText(String.valueOf(c));
  50.    
  51.   }
  52.  
  53.  
  54.  }
  55.  
  56.  public static void main(String args[])
  57.  {
  58.   Ass140 a=new Ass140();
  59.   a.setVisible(true);
  60.   a.setLocation(200,200);
  61.  
  62.  }
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement