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 6921337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:15:51+00:00 2026-05-27T10:15:51+00:00

Following is a program that displays a black screen with a messgage ALARM !

  • 0

Following is a program that displays a black screen with a messgage ALARM ! :

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;


public class displayFullScreen extends Window {
    private JLabel alarmMessage = new JLabel("Alarm !");

    public displayFullScreen() {
        super(new JFrame());
        setLayout(new FlowLayout(FlowLayout.CENTER));
        alarmMessage.setFont(new Font("Cambria",Font.BOLD,100));
        alarmMessage.setForeground(Color.CYAN);
        add(alarmMessage);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        setBounds(0,0,screenSize.width,screenSize.height);
        setBackground(Color.black);

        addKeyListener(new KeyAdapter() {
           @Override
           public void keyPressed(KeyEvent ke) {
                escapeHandler(ke);
           } 
        });
    }

    public void escapeHandler(KeyEvent ke) {
        if(ke.getKeyCode() == ke.VK_ESCAPE) {
            System.out.println("escaped !");
        } else {
            System.out.println("Not escaped !");
        }
    }

    public static void main(String args[]) {
        new displayFullScreen().setVisible(true);
    }
}

I have set a key handler in this program . The handler catches the keys pressed when the focus is on window.
When the escape key will be pressed escaped ! should be displayed otherwise !escaped.
But nothing gets displayed,when i press a key. What is the problem ?

  • 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-27T10:15:52+00:00Added an answer on May 27, 2026 at 10:15 am

    Maybe you want a window but you have two problems:

    1. You should extend JWindow, not Window when using a Swing application
    2. Even extending JWindow won’t work because a JWindow won’t receive KeyEvent unless it is parent JFrame is visible.

    So you should be using a JFrame. If you don’t want the title bar and borders, then you can use an undecorated JFrame.

    Also, you should NOT be using a KeyListener because even on a JFrame key events are only dispatched to the focused component. Instead you should be using Key Bindings. In this case it seems you should be adding the binding to the root pane of the frame.

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

Sidebar

Related Questions

Consider the following simple C program that read a file into a buffer and
the following is a line from a python program that calls the demo.exe file.
I have a program that looks like the following: double[4][4] startMatrix; double[4][4] inverseMatrix; initialize(startMatrix)
I have a program that makes use of the following method to get a
I have a python program that reads floating point values using the following regular
I am trying to write a C++ program that takes the following inputs from
When running a Python program that reads from stdin, I get the following error:
I need to create an installer program that will do install the following: ASP.Net
With win32api, I want that the following program creates two process and creates a
Assume that we have the following code: class Program { static volatile bool flag1;

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.