Recieving Mouse/Keyboard events in independent object?

I'm currently writing a class Map, which is supposed to, surprise, display and handle a map. There is no separate window or similar for it, and thus, I figured that the class using an instance of Map would have to send any events separately to 'their' methods in the object. my question is, is this really necessary, or is there a possibility to register such events directly to the Map class?
what I now have is something like this:
public class Parent extends Applet implements KeyListener {
  Map m = new Map();
  public void init() {
    addKeyListener(this);
//etc.
  public void keyPressed(KeyEvent e) {
    m.keyPressed(e);
} //end of Applet
class Map {
  public Map(){}
  public void keyPressed(KeyEvent e) {
    System.out.println("Recieved key event from Parent: "+e);
}any wise suggestions?
thanks in advance
beaVer

hell, it doesn't work yet. does anybody know what i'm doing wrong?
public class TrivialApplet extends Applet implements KeyListener {
  Map m = new Map();
  public void init() {
    addKeyListener(m);
//etc
class Map implements KeyListener {
  public void keyPressed(KeyEvent e) {
    System.out.println(""+e.getKeyCode());
}it simply doesn't work :/

Similar Messages

  • SWT_AWT mouse/keyboard event trouble

    Hello everyone,
    I have created an ActiveX Component with Visual C++ that uses a WEmbeddedFrame to contain a Swing based GUI. I have copied the code from the SWT_AWT class in the SWT toolkit and it worked fine up to JDK 1.5.0_03.
    Starting with JDK 1.5.0_04 the Swing GUI does no longer receive Mouse/keyboard events.
    I have read through all available material concerning this problem and I have tried the two possible solutions that these documents suggest:
    - called addNotify() on the embedded frame
    - inserted a heavyweight container (java.awt.Panel) between Embedded Frame and the Swing GUI
    However, no luck. The GUI displays fine but does not respond to user actions.
    Does anybody have an idea what might have changed from 1.5.0_03 to 1.5.0_04, that could help me solve this puzzle?
    Thank you very much in advance,
    Helmut

    SWT works up to 1 tree and two text components only. If you have more than that, you windows will get tainted. Basically it's useless to wirte any useful programs for Windows. You never get comaptible latest look from it both mac and windows. Don't waste time for learning it. You better spend time for learning other things. If AWT/Swing is not good enough, learn native languages such as Visual C++/Basic! I have to say SWT wasn't meant to give us better programming platform!

  • Mouse/keyboard events lost during sound events

    I have a new MacbookPro (October 2011, MacBookPro8,2) with 4Gb RAM running latest 10.6.8, and I am extremely frustrated by periodic loss of mouse events (movement freezes, then jumps) and keyboard events (loss of keystrokes) whenever a sound alert is made. Am I the only person experiencing this?

    I should also add a related behavior, repeated keypresses. I do a lot of work on connected unix/linux machines using terminal. Sometimes I will be navigating directories and hit <tab> for command completion, and unexpectedly get the screen scrolling as if I had typed it 100 times!

  • Mouse & Keyboard events

    Hi all,
    I�m creating an applet and this applet needs to use both keyboard and mouse events�. My problem is that when I try to enable mouse events, such as mouse click, using either this.enableEvents(AWTEvent.MOUSE_EVENT_MASK) in init() method, or using mouse listener:
    public class ThreeDSimApplet extends Applet implements Runnable, MouseListener
    and defining the required methods:
    public void mouseClicked(MouseEvent event) {
         if (event.getButton()==MouseEvent.BUTTON1) {
         mouseX=event.getX();
    mouseY=event.getY();
    System.out.println(mouseX+" ," + mouseY);
    public void mousePressed(MouseEvent event) {
    public void mouseReleased(MouseEvent event) {
    public void mouseEntered(MouseEvent event) {
    public void mouseExited(MouseEvent event) {
    the keyboard events become disabled and my keyboard doesn�t works anymore�. Exist a way to use both events in my applet?
    Bye and thanks

    Hi
    This doesn't answer your question exactly, but I suggest implementing
    a MouseAdapter instead of a MouseListener.
    That way you won't have to implement all the unused methods
    (eg mouseEntered, mouseExited etc.); just the one(s) you need
    See http://java.sun.com/docs/books/tutorial/uiswing/events/generalrules.html#eventAdapters
    Good luck for getting an answer to you question!
    lutha

  • How can I (neatly) control mouse click events in a multi-dimensional array?

    Hello everyone!
         I have a question regarding the use of mouse clicks events in a multi-dimensional array (or a "2D" array as we refer to them in Java and C++).
    Background
         I have an array of objects each with a corresponding mouse click event. Each object is stored at a location ranging from [0][0] to [5][8] (hence a 9 x 6 grid) and has the specific column and row number associated with it as well (i.e. tile [2][4] has a row number of 2 and a column number of 4, even though it is on the third row, fifth column). Upon each mouse click, the tile that is selected is stored in a temporary array. The array is cleared if a tile is clicked that does not share a column or row value equal to, minus or plus 1 with the currently targeted tile (i.e. clicking tile [1][1] will clear the array if there aren't any tiles stored that have the row/column number
    [0][0], [0][1], [0][2],
    [1][0], [1][1], [1][2],
    [2][0], [2][1], [2][2]
    or any contiguous column/row with another tile stored in the array, meaning that the newly clicked tile only needs to be sharing a border with one of the tiles in the temp array but not necessarily with the last tile stored).
    Question
         What is a clean, tidy way of programming this in AS3? Here are a couple portions of my code (although the mouse click event isn't finished/working correctly):
      public function tileClick(e:MouseEvent):void
       var tile:Object = e.currentTarget;
       tileSelect.push(uint(tile.currentFrameLabel));
       selectArr.push(tile);
       if (tile.select.visible == false)
        tile.select.visible = true;
       else
        tile.select.visible = false;
       for (var i:uint = 0; i < selectArr.length; i++)
        if ((tile.rowN == selectArr[i].rowN - 1) ||
         (tile.rowN == selectArr[i].rowN) ||
         (tile.rowN == selectArr[i].rowN + 1))
         if ((tile.colN == selectArr[i].colN - 1) ||
         (tile.colN == selectArr[i].colN) ||
         (tile.colN == selectArr[i].colN + 1))
          trace("jackpot!" + i);
        else
         for (var ii:uint = 0; ii < 1; ii++)
          for (var iii:uint = 0; iii < selectArr.length; iii++)
           selectArr[iii].select.visible = false;
          selectArr = [];
          trace("Err!");

    Andrei1,
         So are you saying that if I, rather than assigning a uint to the column and row number for each tile, just assigned a string to each one in the form "#_#" then I could actually just assign the "adjacent" array directly to it instead of using a generic object to hold those values? In this case, my click event would simply check the indexes, one at a time, of all tiles currently stored in my "selectArr" array against the column/row string in the currently selected tile. Am I correct so far? If I am then let's say that "selectArr" is currently holding five tile coordinates (the user has clicked on five adjacent tiles thus far) and a sixth one is being evaluated now:
    Current "selectArr" values:
           1_0
           1_1, 2_1, 3_1
                  2_2
    New tile clicked:
           1_0
           1_1, 2_1, 3_1
                  2_2
                  2_3
    Coordinate search:
           1_-1
    0_0, 1_0, 2_0, 3_0
    0_1, 1_1, 2_1, 3_1, 4_1
           1_2, 2_2, 3_2
                  2_3
         Essentially what is happening here is that the new tile is checking all four coordinates/indexes belonging to each of the five tiles stored in the "selectArr" array as it tries to find a match for one of its own (which it does for the tile at coordinate 2_2). Thus the new tile at coordinate 2_3 would be marked as valid and added to the "selectArr" array as we wait for the next tile to be clicked and validated. Is this correct?

  • Help with possible mouseEvent/Keyboard Event problem

    Hi guys, I am having trouble with a game I am creating right now.  The problem seems to lie on mouse / Keyboard event.
    Basically, I have a character that the player can control using the  keyboard arrow keys and it works perfectly fine on its own.  Whenever the game starts,  the player can control the character instantly with the keyboard. Here's the problem now, after I added another page (at frame 1) and created a start game button, those keyboard events  won't start immediately anymore.  The player must click on the stage  again before it works.  Is there any method to solve this?
    Right now, here is my Start button page.
    var start_btn:Start_btn = new Start_btn;
    start_btn.addEventListener (MouseEvent.CLICK, goGame);
    function goGame(event:MouseEvent) {
    gotoAndStop("game"); //The game's frame
    this.removeEventListener(MouseEvent.CLICK,goGame);
    Here's some code for the actual game part.
    stage.addEventListener(KeyboardEvent.KEY_DOWN,keyP  ressed);
    function keyPressed (e:KeyboardEvent) :void {
    //character movement code...like charcter.x++, x-- etc
    Thanks in advance

    How about trying:
         stage.focus = stage;
    in goGame().

  • In Flashplayer, I can crossover mouse and keyboard events. In IrfanView I cannot. Can this be fixed?

    My client uses IrfanView to play SWF files. Unfortunately, he does not use Flashplayer. In Flashplayer, I can crossover mouse and keyboard events with no problem. In IrfanView, the second I click a button, the keyboard events are disabled. Is there a fix?

    Hi Ned. I may have posted this issue a bit early, but this problem is also happening in Flashplayer 10. It's not exclusive to IrfanView.
    Here is something that I encountered during my testing, when I jump to scene 6 using the menu button, I have a play button to jump from one frame to the next frame that stops -- the keyboard events start working. But if all I am doing is jumping scene to scene with the mouse button, the keyboard events are disabled.
    I feel as if the keyboard events only work if I am playing frames in the scene. And if all I am doing is jumping scene to scene using the buttons, the keys will disable.
    I set up the mouse buttons inside a movieclip that all the scenes share. The mouse actionscript is in the movieclip. On the main timeline of each scene is an actionscript for the keyboard events, even though I had to change each function name.
    I feel the actionscript is setup pretty simple. I just wish clicking the buttons would not disable the keyboard events. This may sound redundant, but the keyboard events do the same thing if you use the mouse buttons. It's just preference for the client even though he will need to understand that using the mouse buttons override the keyboard events. He doesn't really lose functionality.
    Keyboard actionscripting below:
    import flash.events.KeyboardEvent;
    stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyEvent);
    function onKeyEvent(e:KeyboardEvent):void {
    var character:String=String.fromCharCode(e.charCode);
    if (e.keyCode==72) {
      gotoAndStop(1,"master");
    if (e.charCode==49) {
      gotoAndPlay(1,"Distributor");
    if (e.charCode==50) {
      gotoAndPlay(1,"Mirka");
    if (e.charCode==51) {
      gotoAndPlay(1,"Farm");
    if (e.charCode==52) {
      gotoAndPlay(1,"Check2");
    if (e.charCode==53) {
      gotoAndPlay(1,"Check3");
    if (e.charCode==54) {
      gotoAndPlay(1,"Scene2");
    if (e.charCode==55) {
      gotoAndPlay(1,"Scene1");

  • Detect mouse clicks or keyboard events on desktop or everywhere

    Hi,
    What I have to do is to start the application minimized in the system tray. Then the application must be listening for crtl+shift+left mouse click in any part of the desktop or an opened application, when that happens, I have to show a window asking if the user want to take a screenshot starting in the x,y point he clicked and then take the screenshot.
    What I don't know how to do is to detect the mouse and keyboard events when the application is supposed to be running minimized in the system tray.
    How can I do that? Can anybody give me a hint?
    Thanks in advance.

    It's not possible with plain Java. You will need native code for this. Take a look at JNA.

  • Capture All Mouse and Keyboard events even if java window NOT in FOCUS

    Hi All,
    Is this possible to capture all mouse and keyboard events even if java window is not in focus or is minimized. This java program should cature each and every event from the user once the program is started. Any help in this regard is appreciated!
    Thanks&Regards
    Sam

    I don't think you can. (without JNI)

  • Lock all mouse and keyboard event.

    i am looking ways to lock up all the mouse and keyboard events in windows...do u guy have ways to solve this?

    Do you mean that people should not be able to start other applications, or switch to other running applications, before they have typed the right password into you java program? I don't think that can be done in java - it requires more control over the computer than Java typically gives you. You may have some success with full-screen AWT, though.
    But why not use log-on-systems incorporated in whatever operating system you are using? Or some other netware thingie? Honestly, I think you are trying to reinvent the wheel, and even with tool that's not very appropriate.

  • Dispatch loaded clip's keyboard event with parent's mouse click

    Hi. I'm building a swf wrapper which loads third-party swf games. The client would like a button in the wrapper which will dispatch a keyboard event in the loaded swf.
    Can anyone give me hand on how to construct a dispatch event in the wrapper that reaches into the loaded swf?
    Many thanks!

    after loading is complete:
    MovieClip(yourloader.content).dispatchEvent(new KeyboardEvent(somekeyboardevent));   // if the loaded swf is a movieclip

  • Handling keyboard events in applets?! Possible?!

    Hello,
    I wrote a little game that uses keyboard handling events. It is an applet that can also standalone as an application. When i run the program as a standalone application, it handles keyboard inputs fine. ie...i can press the left and right arrow keys and something happens.
    But when i run my program as an applet in a web browser, the applet starts up correctly but does not handle any keyboard events. It only handles mouse events. For instance, if i press the up and down arrow keys, the browser window scrolls up and down!!! And the up and down arrow keys have a specific purpose in my applet.
    QUESTION: how do i get my applet to accept keyboard inputs such as UP,DOWN, LEFT, RIGHT?

    Hmm something went wrong w/ my post so i hope this doesnt show up twice.
    Hey thanks a lot for helping me out. The applet/application is large so here is the main() method and the keyboard event handling class code. My question is how come the keyboard events get properly handled when i run it as a standalone application, but keyboard events go to the browser when i run it as an applet? I would post my entire code but it's over 1000 lines and spread out over 8 files. hehehe.
    Here is main():
      public static void main(String[] args)
          MyProgram applet = new MyProgram();
          applet.isStandalone = true;
          JFrame frame = new JFrame();
          frame.setTitle("Physics: Kinematics");
          frame.getContentPane().add(applet, BorderLayout.CENTER);
          applet.init();                        // initialize the applet inside frame
          applet.addKeyListener(kbHandler);     // kbHandler is a keyboard handling object
          applet.start();
          frame.setSize(APPLETWIDTH,APPLETHEIGHT);
          Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
          frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
          frame.setVisible(true);
          // private inner class to terminate the Application when frame closes
          frame.addWindowListener(
            new WindowAdapter()
                public void windowClosing(WindowEvent e)
                    System.exit(0);
          frame.show();
       }"kbHandler" is the keyboard event handling object. It gets initialized in the applet.init() method.
    kbHandler = new BMkeyboardHandler();And here is the keyboard event handling code:
    // ===== keyboard event handler ===========
       private class BMkeyboardHandler implements KeyListener
            public void keyPressed(KeyEvent e)
                pushedKey = e.getKeyCode();
                // General administrative key actions
                if(pushedKey == KE.VK_H)
                    actionArea.toggleHelpMenu();
                    actionArea.repaint();
                else if(pushedKey == KE.VK_C)
                    actionArea.toggleCtrlMenu();
                    actionArea.repaint();
         }So there it is. Again, the program handles events fine as a standalone application. But running it as an applet in a browser (and even the appletviewer) doesnt let me handle keystrokes.

  • Capture a keyboard event on af:panelGridLayout?

    Hi,
    <af:panelGridLayout> currently supports a client listener with mouse events.
    But I have a requirement where I need to capture keyboard events.
    I tried adding an invisible inputText component on the page and focus on it onclick of the panel.
    My assumption was that when the inputText is on focus, it should be able to capture keyboard events even though its invisible.
    This does not work. Please see code below. The "showAlert" javascript method never gets called.
    <af:inputText clientComponent="true" visible="false" value="dummy" id="keyLink">
         <af:clientListener method="showAlert" type="keyUp"/>
    </af:inputText>
    <af:panelGridLayout id="pgl3">
        <af:clientListener method="toggleRowSelection" type="click"/>
    </af:panelGridLayout>Javascript code:
    function showAlert(event) {
        alert("javascript event " + event.getKeyCode());
    function toggleRowSelection(event) {
        var source = event.getSource();
        var keyLink = source.findComponent("::keyLink");
        keyLink.focus();
        callServerMethod(event);
    };How do I achieve this?
    -Anitha

    "[email protected]" <[email protected]> wrote in message news:[email protected]..
    I have figured out how to add menu Item to an existing EXE program, but I have not yet been able to figure out how to capture there events.&nbsp; Any help would be greatly appreciated.
    It's not entirely clear what you are trying to acieve. I think you're trying to add menu items to an exsisting exe without recompiling it, from LabVIEW. If so the following applies.
    You have to hook the winproc. When a menu item is selected, windows send a message to the window's winproc. There are some API's that can be used to point the address of the winproc to another routine. This routine can do filtering, and then call the original routine.
    Note that LabVIEW doesn't (or didn't until LV7) use windows menu's, so when a LabVIEW (or exe created with LabVIEW) menu item is called, windows will not send anything. That is the price for platform independency.
    I think the OpenG site (or perhaps Winutils from NI) has some vi's to hook windows messages that are send to LabVIEW. Perhaps you can also use them hook another application.
    Regards,
    Wiebe.

  • How to use Mouse Wheel Events

    Hello Everyone
    I am using Datagrid in my Canvas.
    I use mouse wheel to scroll the datagrid. But in one scroll
    through that wheel make the more than 4 rows to be scroll.
    So Now my requirement is to control the delta value of mouse
    wheel event and how to use that with my datagrid so that i will
    able to scroll one row through mouse wheel scroller.
    Thanks

    please give me some suggestion around it.
    I want to scroll one row of datagrid with per mousewheel
    scroll. I am not getting how to use the scrollMouseWheelMultiplier
    property of the IConfiguration class because i am not able to
    create the object of this class.
    I am using the Flex 3.0 and flash 9 version.
    please help me out around this.

  • Why and how to use events in abap objects

    Dear all,
      Please explain me why and how to use events in abap objects with real time example
    regards
    pankaj giri

    Hi Pankaj,
    I will try to explain why to use events... How to use is a different topic.. which others have already answered...
    This is same from your prev. post...
    Events :
    Technically speaking :
    " Events are notifications an object receives from, or transmits to, other objects or applications. Events allow objects to perform actions whenever a specific occurrence takes place. Microsoft Windows is an event-driven operating system, events can come from other objects, applications, or user input such as mouse clicks or key presses. "
    Lets say you have an ALV - An editable one ...
    Lats say - Once you press some button  you want some kind of validation to be done.
    How to do this ?
    Raise an Event - Which is handled by a method and write the validation code.
    Now you might argue, that I can do it in this way : Capture the function code - and call the validate method.
    Yes, in this case it can be done.. But lets say .. you change a field in the ALV and you want the validation to be done as soon as he is done with typing.
    Where is the function code here ? No function code... But there is an event here - The data changed event.
    So you can raise a data changed event that can be handled and will do the validation.
    It is not user friendly that you ask the user to press a button (to get the function code) for validation each time he enters a data.
    The events can be raised by a system, or by a program also. So in this case the data changed event is raised by a system that you can handle.
    Also, Lets say on a particular action you want some code to trigger. (You can take the same example of validation code). In this case the code to trigger is in a separate class. The object of which is not available here at this moment. (This case happens very frequently).
    Advantage with events : Event handlers can be in a separate class also.
    e.g : In the middle of some business logic .. you encounter a error. You want to send this information to the UI (to user - in form of a pop up) and then continue with some processing.
    In many cases - A direct method call to trigger the pop up is not done. Because (in ideal cases) the engine must not interact with UI directly - Because the UI could be some other application - like a windows UI but the error comes from some SAP program.
    So - A event is raised from the engine that is handled in the UI and a pop up is triggered.
    Here -- I would have different classes (lets say for different Operating Systems). And all these classes must register to the event ERROR raised in application.
    And these different classes for different Operation systems will have different code to raise a pop-up.
    Now you can imagine : If you coded a pop-up for Windows (in your application logic) .. it will not work for Mac or Linux. But of you raise a event.. that is handled separately by a different UI classes for Win, Linux or Mac  they will catch this event and process accordingly.
    May be I complicated this explanation .... but I couldn't think of a simpler and concrete example.
    Cheers.
    Varun.

Maybe you are looking for

  • PE7 unable to recognize Canon HV20 as High Definition

    Hello Everyone: Unfortunately like some of you that probably want to try your hand at high definition editing, I just bought PE7 a couple of days before the announcement for PE8. For some reason I find that PE7 (and my previous PE3) cannot recognize

  • How do I disable the paste function on a PDF so that the reader can write text on it but not copy and paste text onto it?

    I'm trying to create a PDF for my students to take notes on during class but I don't want them to be able to copy and paste the notes. I'm using adobe professional to create the PDF.

  • ABAP/4 processor: DBIF_RSQL_SQL_ERROR

    We are running the below on an AS/400 model 840 with v5r2: Module     Version     Patch     Service Pack SAP_BASIS     620     54     SAPKB62054 SAP_ABA     620     54     SAPKB62054 SAP_BW     30B     25     SAPKW30B25 PI_BASIS     2003_1_6201     7

  • Connection Object Error

    Hi, When i create an Connection oBject in the fresh system,the system throws the below error message: ""Error in reading table EFISEL Message no. E9014 Diagnosis An error occurred during reading of one or more table entries. This error was reported b

  • Coonect by clause

    Hi this is my table data CODE     HBL     EVENT     EDATE CN     000-0106 ISCD     200507111628 CN     000-0106 IARV     200506131407 CN     000-0106 IARV     200506171187 CN     000-0306 ISCD     200506031035 CN     000-0306 IARV     200504011004 CN