import java.awt.*;
import java.awt.event.*;
public class GUIFrame extends Frame
{
private Label l1,l2;
TextField t1,t2,t3;
Button badd;
public GUIFrame()
{
super("GUI Application");
setLayout(new FlowLayout());
l1 = new Label("Enter First Number:");
l2 = new Label("Enter Second Number:");
t1 = new TextField(20);
t2 = new TextField(20);
t3 = new TextField(20);
badd = new Button("Add");
add(l1);
add(t1);
add(l2);
add(t2);
add(t3);
add(badd);
badd.addActionListener(new ListenEvent(this)); /*Registration of the button with the event Listener Interface */
setSize(400,300);
setVisible(true);
}
public static void main(String args[])
{
GUIFrame g = new GUIFrame();
}
}
class ListenEvent implements ActionListener
{
GUIFrame g1;
ListenEvent(GUIFrame g1)
{
this.g1 = g1;
}
public void actionPerformed(ActionEvent e)
{
int n1,n2;
n1 = Integer.parseInt(g1.t1.getText());
n2 = Integer.parseInt(g1.t2.getText());
g1.t3.setText(String.valueOf(n1+n2));
}
}
No comments:
Post a Comment