AWT Program to display the given input on button click

This is a program which will accept the input from the keyboard and on clicking the button, it will show the given input. This program is compiled in Eclipse. This is a basic program in Java using AWT where a single TextField, Label and a Button is used.

Screenshot


The Code:
package dProBuk;

import java.awt.Button;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class SimpleLayoutAWT implements ActionListener
{
 TextField t;
 Label l;
 Button b;
 public SimpleLayoutAWT() {
  // TODO Auto-generated constructor stub
  Frame f=new Frame("Simple Frame");
  t=new TextField("Enter the Name");
  l=new Label("");
  b=new Button("Show !");
  f.setLayout(new GridLayout(3,1));
  f.setVisible(true);
  f.setSize(500,200);
  f.add(t);
  f.add(b);
  f.add(l);
  b.addActionListener(this);
  f.addWindowListener(new WindowAdapter() {
          public void windowClosing(WindowEvent windowEvent){
              System.exit(0);
           }        
        });    
 }
 public static void main(String []args)
 {
  new SimpleLayoutAWT();
 }

 @Override
 public void actionPerformed(ActionEvent e) {
  // TODO Auto-generated method stub
  l.setText("Hello "+t.getText());
 }

}


Got doubts, Comment them here !

Comments

Popular posts from this blog

Non Restoring Division Algorithm Implementation in C

Hackerrank Modified Kaprekar Numbers Solution

Bit Stuffing Code Implementation in Java