currently i am facing a problem for these method. when my program copying or cutting a selected text and paste to another selected area, unexpected result, it paste the selected text to all of the fields and areas of my program.
is there anyway to check current selected area or maybe there is other way out to solve this problem?

*equipmentArea and area are objects of JTextArea
* the rest are objects of JTextField

MainTabbed mPane = new MainTabbed();
.
.
.
.
 class CopyActionAdapter implements ActionListener{
         UIAFrame adaptee;
         //JTextArea jTextArea = new JTextArea(textArea);
         
          CopyActionAdapter(UIAFrame adaptee){
            this.adaptee = adaptee;
         }
         
          public void actionPerformed( ActionEvent e ) 
         {
            
            mPane.locField.copy();            
            mPane.area.copy();
            mPane.dateField.copy();
            mPane.ndBuddyField.copy();
            mPane.depthField.copy();
            mPane.firstBuddy.copy();
            mPane.weightField.copy();
            mPane.timeInField.copy();
            mPane.tOutField.copy();
            mPane.startTimeField.copy();
            mPane.sTimeField.copy();
            mPane.bTimeField.copy();
            mPane.startField.copy();
            mPane.finishField.copy();
            mPane.airField.copy();
            mPane.surfaceField.copy();
            mPane.bottomField.copy();
            mPane.equipmentArea.copy();
            mPane.waterTypeField.copy();
            mPane.visiField.copy();
            mPane.diveLogField.copy();
            mPane.diveNoField.copy();
         
         }
      }



class PasteActionAdapter implements ActionListener{
         UIAFrame adaptee;
         //JTextArea jTextArea = new JTextArea(textArea);
         
          PasteActionAdapter(UIAFrame adaptee){
            this.adaptee = adaptee;
         }
         
          public void actionPerformed( ActionEvent e ) 
         {
            mPane.area.paste();
            mPane.locField.paste();
            mPane.dateField.paste();
            mPane.ndBuddyField.paste();
            mPane.depthField.paste();
            mPane.firstBuddy.paste();
            mPane.weightField.paste();
            mPane.timeInField.paste();
            mPane.tOutField.paste();
            mPane.startTimeField.paste();
            mPane.sTimeField.paste();
            mPane.bTimeField.paste();
            mPane.startField.paste();
            mPane.finishField.paste();
            mPane.airField.paste();
            mPane.surfaceField.paste();
            mPane.bottomField.paste();
            mPane.equipmentArea.paste();
            mPane.waterTypeField.paste();
            mPane.visiField.paste();
            mPane.diveLogField.paste();
            mPane.diveNoField.paste();
         
         }
      }

Use e.getSource() to determine where to copy / paste to / from rather than mPane.field. For example, your PasteActionAdapter.actionPerformed method should be:

public void actionPerformed(ActionEvent e)
{
  e.getSource().paste();
}

Use e.getSource() to determine where to copy / paste to / from rather than mPane.field. For example, your PasteActionAdapter.actionPerformed method should be:

public void actionPerformed(ActionEvent e)
{
  e.getSource().paste();
}

im sorry to tell u that, it doesn't work :(

---error message---
cannot find symbol
symbol: method paste()
location: class java.lang.Object
e.getSource().paste();

You need to cast e.getSource() to an appropriate type that implements the paste() method.

You need to cast e.getSource() to an appropriate type that implements the paste() method.

i've tried that, but the paste() seem not working

((JTextArea)e.getSource()).paste();

Well, if that action listener is attached to a button, then the source will be that button and has nothing to do with the component that you want to act upon. So I don't think you really want to call paste on that anyway. I was merely addressing the casting problem.

You may want to take a look through some of the tutorial on implementing copy and paste: http://java.sun.com/docs/books/tutorial/uiswing/dnd/textpaste.html

thanks for the website, it's helped me a lot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.