event to JTextArea

0

Hello, how could you help me? I am new to the topic of events in java.

I have this class, which simply creates a form with 2 JTextArea objects.

I would like to know how to print a hello on the console by alternating the cursor position between the 2 JTextArea objects; that is to say if for example I write something in ct and then I click on ct2 that prints in console "hello"

package javaapplication1;
import javax.swing.*;

import javax.swing.JButton;
import javax.swing.JFrame;



public class JavaApplication1 extends JFrame
{
    private JTextArea ct;
    private JTextArea ct2;

    public JavaApplication1()
    {

        setLayout (null);
        ct = new JTextArea();
        ct.setSize(75,30);    
        ct.setLocation(0, 0);
        add(ct);

        ct2 = new JTextArea();
        ct2.setSize(75,30);    
        ct2.setLocation(100, 0);
        add(ct2);

    }



    public static void main(String[] args) 
    {
       JavaApplication1 v1 = new JavaApplication1();
       v1.setVisible(true);
       v1.setSize(200, 200);

    }



}
    
asked by Abner 17.04.2017 в 20:12
source

1 answer

0
nombreDelTextArea.addMouseListener(new MouseListener() {

    public void mouseClicked(MouseEvent e) {

    }
});

I think it was something like that, look to see if it's worth it.

    
answered by 21.04.2017 в 09:52