0

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();

    }

}
2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Kert
0

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.

0

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

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

Edited by Kert

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.