Action listener program in Java programming

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

public class window extends JFrame implements ActionListener{

JTextArea t1= new JTextArea("default text",2,25);

JTextArea t2=new JTextArea(2,25);

JButton b=new JButton("Copy");

public window(){

super ("Hello World");

setSize(400,200);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setVisible(true);

Container c=getContentPane();

c.setBackground(Color.black);

c.setLayout(new FlowLayout());

b.addActionListener(this);

c.add(b);

c.add(t1);

c.add(t2);

setContentPane(c);

}

public void actionPerformed(ActionEvent event){

t2.setText(t1.getText());

}

public static void main(String args[]){

window w=new window();

}

}

Comments