JAVA Program to Display Textbox and Button When Button Pressed Display Message in Textbox

JAVA Program to Display Textbox and Button When Button Pressed Display Message in Textbox:


/*

<APPLET
 CODE = buttontest.class
 WIDTH=400
 HEIGHT=200>
 </APPLET>
*/
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class buttontest extends Applet
                         implements ActionListener
                         
{
   TextField t1;
   Button b1;
   
   public void init()
   {
    t1 = new TextField(20);
    add(t1);
    b1= new Button("Click Here!");
    add(b1);
    b1.addActionListener(this);
   }
   
   
    public void actionPerformed(ActionEvent e)
    {
      String msg = new String("Welcome to Java");
      if(e.getSource()==b1)
      {
       t1.setText(msg);
      } 
    }
}

OUTPUT:

JAVA Program to Display Textbox and Button When Button Pressed Display Message in Textbox


Leave a Reply

Your email address will not be published. Required fields are marked *

5 × four =