Hey,
I have a problem that I've been messing with for several hours, but with no result. I have a basic textfield where I can enter some info and I have to be able to read it and save it to a static variable by both pressing "Enter" and clicking on a simple JButton.

Here is the keyboard listener, but I have no idea how to do the same stuff with mouse... thanks!

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


public class KastiKuulaja implements ActionListener {

    @Override
    public void actionPerformed(ActionEvent e) {
        Manguvali.kasutajaSisend = e.getActionCommand().toLowerCase();

    }

}

You'd use a mouse listener. When you click on a component with a mouse listener the listener method would be called the same as the action listener.

But how can I read the text from JTextField. That confuses me the most.

E: Got it. Had to use JTextFields' getText() method. Thanks!

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.