d.Program on TextArea with copy,cut and paste buttons.

Code:-

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

class TextAreaDemo1 extends JFrame implements ActionListener

{

JTextArea txt;

JButton btnCut,btnCopy,btnPaste;

JPanel p1,p2;

TextAreaDemo1()

{

setTitle("JTextArea Demo");

   setSize(400, 400);

   setVisible(true);

   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

txt=new JTextArea(10,30);

  btnCut=new JButton("CUT");

btnCopy=new JButton("COPY");

btnPaste=new JButton("PASTE");

p1=new JPanel();

p2=new JPanel();

JScrollPane sp=new JScrollPane(txt);

p1.add(txt);

p2.add(btnCut);

p2.add(btnCopy);

p2.add(btnPaste);

btnCut.addActionListener(this);

btnCopy.addActionListener(this);

btnPaste.addActionListener(this);

getContentPane().add(p1,BorderLayout.CENTER);

getContentPane().add(p2, BorderLayout.SOUTH);

}

public void actionPerformed(ActionEvent ae)

{

if(ae.getSource()==btnCut)

{

txt.cut();

}

else if(ae.getSource()==btnCopy)

{

txt.copy();

}

else if(ae.getSource()==btnPaste)

{

txt.paste();

}

}

public static void main(String args[])

{

new TextAreaDemo1();

}

}

 

O/P:

Programs based on AWT and Swing.




Post a Comment

0 Comments