Results 1 to 2 of 2
  1. #1
    susan is offline Member
    Join Date
    Jul 2007
    Posts
    44
    Rep Power
    0

    Default Help with import AWTKeyStroke and swing.KeyStroke

    What do you need to import to instantiate a newly KeyStroke object? Here's the code I have:
    Java Code:
    import java.awt.AWTKeyStroke;
    import javax.swing.KeyStroke;
    ...
    KeyStroke k = new KeyStroke();
    ...
    System.out.println("Type something: ");
    key = k.getKeyStroke();
    System.out.println("The key you pressed was: "+key+".\n");
    ...
    When I compile the program I get.
    Java Code:
    --------------------Configuration: <Default>--------------------
    C:\Documents and Settings\admin\Desktop\KeyLogger.java:19: cannot resolve symbol
    symbol : constructor KeyStroke ()
    location: class javax.swing.KeyStroke
    KeyStroke k = new KeyStroke();
    ^
    C:\Documents and Settings\admin\Desktop\KeyLogger.java:26: cannot resolve symbol
    symbol : method getKeyStroke ()
    location: class javax.swing.KeyStroke
    key = k.getKeyStroke();
    Thanks.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    cannot resolve symbol
    symbol : constructor KeyStroke ()
    location: class javax.swing.KeyStroke
    KeyStroke k = new KeyStroke();
    The compiler is telling you it cannot find a no–argument Keystroke constructor.
    Look in the KetStroke class api. There are no constructors. All KeyStroke instances are obtained from the static methods.
    Java Code:
    KeyStroke k = KeyStroke.getKeyStroke(5 possible args);
    cannot resolve symbol
    symbol : method getKeyStroke ()
    location: class javax.swing.KeyStroke
    key = k.getKeyStroke();
    Same thing: can't find a method getKeyStroke called on a KeyStroke instance. Check the api. A KeyStroke instance is already a KeyStroke.
    Java Code:
    KeyStroke keyStroke = KeyStroke.getKeyStroke("UP");

Similar Threads

  1. how to import a picture into an applet
    By cecily in forum Java Applets
    Replies: 2
    Last Post: 01-15-2010, 08:51 PM
  2. how to read single Keystroke without using return
    By oomanamemni in forum New To Java
    Replies: 1
    Last Post: 02-14-2008, 07:21 PM
  3. import statement.
    By diRisig in forum New To Java
    Replies: 2
    Last Post: 02-08-2008, 12:34 AM
  4. how to import jface in java swt
    By rajaletchumy in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 12:31 AM
  5. I can't import javax.mail
    By katie in forum New To Java
    Replies: 2
    Last Post: 08-04-2007, 05:05 PM

Posting Permissions

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