/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package excel;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
*
* @author rajitha
*/
public class addition extends JFrame {
JTextField txt1, txt2;
JLabel lbl1, lbl2;
JButton btn1;
JPanel panel;
public addition() {
super("Integer Addition");
panel = new JPanel(new GridLayout(3, 2));
txt1 = new JTextField();
txt2 = new JTextField();
lbl1 = new JLabel("Integer 1 :- ");
lbl2 = new JLabel("Integer 2 :- ");
btn1 = new JButton("Add");
panel.add(lbl1);
panel.add(txt1);
panel.add(lbl2);
panel.add(txt2);
panel.add(btn1);
add(panel);
setLocationRelativeTo(null);
setSize(200, 150);
addAction();
}
void addAction() {
btn1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int no1 = Integer.parseInt(txt1.getText());
int no2 = Integer.parseInt(txt2.getText());
JOptionPane.showMessageDialog(null, "Result = " + (no1 + no2));
}
});
}
public static void main(String[] args) {
addition a=new addition();
a.setVisible(true);
a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}