Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6953065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:25:50+00:00 2026-05-27T14:25:50+00:00

During writing this code I realized if making into a jar there would have

  • 0

During writing this code I realized if making into a jar there would have to be a graceful way to close the program. I have chosen to use the key ‘F1’. I’ve researched a few articles online and found that the way I’m trying to handle it should be a viable approach, but the program doesn’t even seem to fire the event method. The system.out.println never displays.

import java.applet.Applet;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Random;


public class MouseMove extends Applet implements KeyListener{

public static Random randomGenerator = new Random();
public static int code;

public void init(){
    addKeyListener(this);
}

public void keyPressed(KeyEvent evt){
    code = evt.getKeyCode();
    System.out.println("Key: "+KeyEvent.getKeyText(code));

    if(code == KeyEvent.VK_F1){
        System.exit(0);
    }
}

public void keyTyped(KeyEvent e){   
}
public void keyReleased(KeyEvent e){
}

public static void main(String[] args) {
    // TODO Auto-generated method stub
    try {

        Robot robot = new Robot();          

        while(true){

            robot.mouseMove((int)(Math.random()*1366), (int)(Math.random()*768));
            robot.delay(5000);
            robot.mouseWheel((int)(Math.random()*786));
            robot.delay(5000);
        }
    } catch (AWTException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}//main

}//class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:25:51+00:00Added an answer on May 27, 2026 at 2:25 pm
    1. KeyListener works only if Component has Focus in the Window.

    2. You have to create a visible Container.

    3. setFocusable() for Component

    4. Better would be use Swing JComponent.

    5. Use JFrame instead of JApplet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

During a typical day programming, I implement functions in a way that I would
I am currently writing my own shell program. This simple shell can just execute
I am writing this application in Java, where I have a JTree on the
I am writing tests and I wonder if there is a way to change
I have been writing a small application using C# to copy a document into
I'm writing some code which processes a queue of items. The way it works
I hope this isn't a stupid question. However I am writing a program at
So I have a very weird problem. I am writing some code in VB.Net
During a Mix10 presentation , the presenter (Charlie Kindel) said that when writing Silverlight
During a discussion about security, a developer on my team asked if there was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.