Skip to content

A simple frame design with event model

by on February 20, 2011

import java.awt.*;

import java.awt.event.*;

class eventmodeling extends Frame implements ActionListener

{

Button b;

TextField t;

eventmodeling()

{

b=new Button(“Click Here and Get it Displayed”);

t=new TextField(30);

setLayout(new FlowLayout(FlowLayout.CENTER));

add(t);

add(b);

b.addActionListener(this);

}

public void actionPerformed(ActionEvent e)

{

String s=e.getActionCommand();

if(s.equals(“Click Here and Get it Displayed”))

t.setText(“Haha!!! Displayed”);

}

public static void main(String args[])

{

eventmodeling z=new eventmodeling();

z.setSize(300,300);

z.setVisible(true);

}

}

 

Output of above program

Leave a Comment

Leave a comment