Results 1 to 3 of 3
  1. #1
    ryanmk54's Avatar
    ryanmk54 is offline Member
    Join Date
    May 2011
    Posts
    18
    Rep Power
    0

    Question mouse click listener from textfield

    I am making a calculator that will find the answer of two numbers. x + y = answer for example. There is a textfield for xInput, yInput, operatorInput, and answer. There are also numbered buttons 0-9. When you press 0, it will add a zero to x or y depending on which textfield is selected. When you click on a text field I want it to select it. Is there a way to give both xInput and yInput the same listener?

  2. #2
    RichersooN is offline Senior Member
    Join Date
    Jan 2011
    Location
    Rizal Province, Philippiines
    Posts
    167
    Rep Power
    0

    Default

    #1 yes create a subclass inside the class.
    Java Code:
    textFieldEvent et = new textFieldEvent ();
    		table.addActionListener(et);
    		table.addActionListener(et);
    
    public class textFieldEvent extends ActionListener{
    .
    .
    .
    }
    #2 or create method

  3. #3
    ryanmk54's Avatar
    ryanmk54 is offline Member
    Join Date
    May 2011
    Posts
    18
    Rep Power
    0

    Default

    Quote Originally Posted by RichersooN View Post
    #1 yes create a subclass inside the class.
    Java Code:
    textFieldEvent et = new textFieldEvent ();
    		table.addActionListener(et);
    		table.addActionListener(et);
    
    public class textFieldEvent extends ActionListener{
    .
    .
    .
    }
    #2 or create method
    I would want it to be a mouse listener ".addMouseListener()" for when the user clicks on the textfield. I found a method in the ActionEvent class to differentiate which textfield was clicked but not the MouseEvent class. Is there a way to differentiate which textfield was clicked?

Similar Threads

  1. Need Help with Mouse Listener!!!!
    By Doggir in forum New To Java
    Replies: 11
    Last Post: 05-05-2011, 11:48 PM
  2. Mouse Listener
    By Quizerno in forum New To Java
    Replies: 8
    Last Post: 03-17-2011, 05:25 AM
  3. Mouse Listener for mouse floating over object?
    By Krooger in forum AWT / Swing
    Replies: 1
    Last Post: 11-18-2009, 04:34 AM
  4. Replies: 6
    Last Post: 03-17-2009, 02:23 AM
  5. mouse click alert
    By amir in forum AWT / Swing
    Replies: 1
    Last Post: 08-05-2008, 10:42 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •