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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:37:51+00:00 2026-05-25T16:37:51+00:00

In passive rendering mode one can use KeyListener and ActionListener interfaces to handle events

  • 0

In passive rendering mode one can use KeyListener and ActionListener interfaces to handle events from user.

What is the correct way of event handling in full screen mode? Please extend this skeleton providing implementation for mouse click and key press events, please don’t bloat your example (the example starts full screen exclusive mode, using a Timer to update graphics in window):

import java.applet.Applet;
import java.awt.Color;
import java.awt.DisplayMode;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferStrategy;
import javax.swing.JFrame;
import javax.swing.Timer;

public class applet extends Applet
{
    Timer timer;
    JFrame frame;
    DisplayMode[] displayModes = new DisplayMode[] {
            new DisplayMode(1280, 800, 32, 60)
    };

    BufferStrategy bufferStrategy;
    Rectangle bounds;

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    /**
     * @param args
     */

    public void init()
    {

        GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); //displays, fonts, color shemes...
        GraphicsDevice device = env.getDefaultScreenDevice(); //for one-display systems

        setIgnoreRepaint(true);

        GraphicsConfiguration gc = device.getDefaultConfiguration();
        frame = new JFrame(gc);

        device.setFullScreenWindow(frame);

        if (device.isDisplayChangeSupported())
            device.setDisplayMode(displayModes[0]);

        frame.createBufferStrategy(2);
        bufferStrategy = frame.getBufferStrategy();

        timer = new Timer(1000 / 50, new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                Graphics2D g = null;
                try {
                    g = (Graphics2D) bufferStrategy.getDrawGraphics();
                    render(g);
                } finally {
                    g.dispose();
                }
                bufferStrategy.show();
            }

        });

    }

    private void render(Graphics2D g) {
        g.setColor(Color.BLACK);
        g.fillRect(0, 0, bounds.width, bounds.height);
    }

    public void start()
    {
        timer.start();

    }

    public void stop()
    {
        timer.stop();
    }

}
  • 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-25T16:37:52+00:00Added an answer on May 25, 2026 at 4:37 pm

    It looks like the usual approaches shown in How to Use Key Bindings and How to Write a Mouse Listener work correctly in Full-Screen Exclusive Mode.

    import java.awt.Color;
    import java.awt.EventQueue;
    import java.awt.GraphicsDevice;
    import java.awt.GraphicsEnvironment;
    import java.awt.event.ActionEvent;
    import java.awt.event.KeyEvent;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.event.WindowEvent;
    import javax.swing.AbstractAction;
    import javax.swing.Action;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.KeyStroke;
    
    /** @see http://stackoverflow.com/questions/7456227 */
    public class FullScreenTest extends JPanel {
    
        private static final String EXIT = "Exit";
        private JFrame f = new JFrame("FullScreenTest");
        private Action exit = new AbstractAction(EXIT) {
    
                @Override
                public void actionPerformed(ActionEvent e) {
                    f.dispatchEvent(new WindowEvent(
                        f, WindowEvent.WINDOW_CLOSING));
                }
            };
        private JButton b = new JButton(exit);
    
        public FullScreenTest() {
            this.add(b);
            f.getRootPane().setDefaultButton(b);
            this.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_Q, 0), EXIT);
            this.getActionMap().put(EXIT, exit);
            this.addMouseMotionListener(new MouseAdapter() {
    
                @Override
                public void mouseMoved(MouseEvent e) {
                    FullScreenTest.this.setToolTipText(
                        "("+ e.getX() + "," + e.getY() + ")");
                }
            });
        }
    
        private void display() {
            GraphicsEnvironment env =
                GraphicsEnvironment.getLocalGraphicsEnvironment();
            GraphicsDevice dev = env.getDefaultScreenDevice();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setBackground(Color.darkGray);
            f.setResizable(false);
            f.setUndecorated(true);
            f.add(this);
            f.pack();
            dev.setFullScreenWindow(f);
        }
    
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    new FullScreenTest().display();
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So..I intend to use a Model View Presenter(the passive mode, in which the UI
When programming through sockets in C, one can automatically get information about their interfaces
How do I overcome Please login with USER and PASS. Passive mode refused. errors?
i'm getting error in java ftp code. SimpleFTP could not request passive mode. i
I'm working with the Passive View pattern. The user clicks a new account button.
Can someone tell me what is the difference between active and passive FTP? Which
in a classic Passive-MVP pattern, how can i avoid a reference of the presenter
I'm trying to understand how to use Passive View correctly. It seems to me
I have written an FTP client to automatically enter passive mode and subsequently connect
Is it possible to set FTP passive or active mode when working with URLConnection

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.