Java

Java Applet - Button Component Demonstration

Java Applet - Button Component Demonstration
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class butexam1 extends Applet
{
TextField t1,t2;
Button b1,b2,b3;


public void init()
{
t1 = new TextField(10);
t2 = new TextField(10);

b1 = new Button("Enter");
b2 = new Button("Next");
b3 = new Button("Clear");

b1.addActionListener(new a());
b2.addActionListener(new a());
b3.addActionListener(new a());

add(t1); add(t2); add(b1); add(b2);add(b3);
}

class a implements ActionListener
{
public void actionPerformed(ActionEvent ee)
{
if(ee.getSource() == b1)
{
t1.setText("Welcome");
}

if(ee.getSource() == b2)
{
t2.setText("Have a Nice Day");
}

if(ee.getSource() == b3)
{
t1.setText("");
t2.setText("");
}

}
}

}

/* <applet code = "butexam1.class" height = 300 width = 300>
</applet> */
Senthilvelan Sambamoorthy

Senthilvelan Sambamoorthy is working as a Professor in Department of Master of Computer Applications, Paavai Engineering College, Namakkal, Tamilnadu, India, He is Masters in Computers Applications. Having 18+ years of experience and his area of interest is Java, JSP, Servlet, J2EE, C#, PHP, Python ASP.NET, SQL Server and etc.