Results 1 to 5 of 5
  1. #1
    dilpreet28 is offline Member
    Join Date
    Jun 2010
    Posts
    23
    Rep Power
    0

    Default Key Binding problem

    I am trying to do key binding
    this is my code

    public Buttons() {
    initComponents();
    btn1.getInputMap(jPanel1.WHEN_IN_FOCUSED_WINDOW).p ut(KeyStroke.getKeyStroke("ENTER"),"open project");
    btn1.getActionMap().put("open project", new actionPerformed());
    }
    public void actionPerformed(ActionEvent e) {
    JOptionPane.showMessageDialog(null, "You Clicked BTN1");
    }

    but in the getActionMap where it says new actionPerformed(), Netbeans puts a red line underneath it and on rollover it says
    cannot find symbol
    symbol: class actionPerformed
    location: class Buttons

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,449
    Rep Power
    25

    Default

    Where did you get this code from?
    actionPerformed() is the name of the method in the ActionListener interface.
    What is supposed to be the second parameter to the put() method?

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Agrees with Norm -- if you have an error then you should check the API to make sure that your method calls have the right format.

    But having said that, if you're trying to trap the enter key to make one JButton the default button, there's an easier way. Please check out JRootPane's setDefaultButton method.

  4. #4
    dilpreet28 is offline Member
    Join Date
    Jun 2010
    Posts
    23
    Rep Power
    0

    Default

    I got the key binding code from a forum post and i wrote the actionPerformed function. I wrote a public function for the actionPerformed and tried to use it in the getActionMap(). This is just a small trial, i want to do this to a bunch of buttons and with different keys so i thought i should try and do it to one first.

  5. #5
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    Did you look at the API as Norm suggested? Do you realize that actionPerformed is not a class but is a method of an interface and several Abstract and concrete classes?

Similar Threads

  1. JAXB Binding
    By Fusebox in forum XML
    Replies: 0
    Last Post: 06-11-2010, 10:06 PM
  2. dynamic binding
    By apparao in forum New To Java
    Replies: 1
    Last Post: 02-16-2010, 08:41 AM
  3. [SOLVED] Key binding Q
    By playwin2 in forum New To Java
    Replies: 3
    Last Post: 11-04-2008, 06:04 AM
  4. Spring binding in jsp
    By Pierre Javason in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 05-05-2008, 12:21 PM
  5. Dynamic Binding
    By javarishi in forum New To Java
    Replies: 3
    Last Post: 04-09-2008, 11:17 AM

Posting Permissions

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