Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

standalone java application

  Asked By: Caleb    Date: May 09    Category: Java    Views: 896
  

I have one question. I have a standalone java application and that
application contain one TextArea. I want to add three buttons in
that application "Select All", "Copy" "Paste". So, when user click
on Select All then everything in that text area should get selected
and same thing with Copy and Paste. Can anyone please send me a
example of how to do that. I would really appriciated your help.
Thanks you very much for your help.

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Vivian Ruiz     Answered On: May 09

Heres my program:

// SelectCopyPaste.java by Firefox 6 June 2003

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class SelectCopyPaste extends Frame
{
Button select  = new Button ("Select all");
Button copy  = new Button ("Copy");
Button paste  = new Button ("Paste");
Button quit = new Button ("Exit");
TextArea t1 = new TextArea (20, 20);
String s;
public SelectCopyPaste ()
{
setLayout (new BorderLayout ());
Panel pp = new Panel ();
pp.setLayout (new FlowLayout ());
select.addActionListener (new Selecter ());
copy.addActionListener (new Copier ());
paste.addActionListener (new Paster ());
quit.addActionListener (new Quitter ());
pp.add (select);
pp.add (copy);
pp.add (paste);
pp.add (quit);
add (pp, BorderLayout.NORTH);
add (t1, BorderLayout.CENTER);
}


public static void main (String [] args)
{
Frame f = new SelectCopyPaste ();
f.setSize (400, 400);
f.setVisible (true);
}


class Quitter implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
System.exit (0);
}
}


class Selecter implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
t1.selectAll ();
t1.requestFocus ();
}
}


class Copier implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
s = t1.getSelectedText ();
t1.requestFocus ();
}
}


class Paster implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
t1.insert (s, t1.getCaretPosition ());
t1.requestFocus ();
}
}
}

 
Didn't find what you were looking for? Find more on standalone java application Or get search suggestion and latest updates.




Tagged: