Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  How do I take input from full screen mode?  (Read 2420 times)
0 Members and 1 Guest are viewing this topic.
Offline bert

Junior Devvie

Miles of road and miles of code

« Posted 2006-06-20 18:26:35 »

I've been working on a game and it's the first time I've worked with anything full screen before. Up until now I never cared if I had to stick my game into a JFrame but this is for the GameDev Four Elements Contest and I figured full screen would make a better impression. (I've never entered any contest at all before.)

So I started to set up the Game class somewhat like this:

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.geom.*;
public class Game extends JApplet implements KeyListener{
   public static boolean forceWindow=false;
   ImageIcon mainmenu=new ImageIcon("Title Screen.jpg");
   Image buff; Graphics backg;
   static GraphicsEnvironment gfxenv;
   static GraphicsDevice screen;
   public static final DisplayMode[] wishList={};
   public static DisplayMode originalMode;
   public void keyPressed(KeyEvent e){
   public void keyReleased(KeyEvent e){}
   public void keyTyped(KeyEvent e){}
   public void init(){
   public void paint(Graphics g){
   public static void main(String[] args){
      JFrame frame=new JFrame("My Supercool Game");
      originalMode=screen.getDisplayMode();   //****** this line gives me problems as well
      if(args.length>0&&args[0].equals("window")) forceWindow=true;
         Insets i=frame.getInsets();
      Game g=new Game();
      g.init(); g.start();

So I ran something similar to this and it got me to full screen, but then it was stuck. I tried Alt+Esc, I tried Ctrl+Alt+Del, I tried pressing the Escape key. Nothing at all worked. I had to hold the power button on my computer to get it to shut off, thereby ending the program. It won't even respond when I force windowed mode. (However, then it's a JFrame which gives me that nice X in the corner.)

Also, you may have noticed the line I marked that gave me problems. This line compiles fine, but gives me the exception below and then ends when I try running it.

Exception in thread "main" java.lang.InternalError: Could not get display mode
        at sun.awt.Win32GraphicsDevice.getCurrentDisplayMode(Native Method)
        at sun.awt.Win32GraphicsDevice.getDisplayMode(Unknown Source)
        at Game.main(

I'm not sure how to work around this, but I've heard that internal errors are "very rare, and there's usually nothing you can do about them when they pop up." What I'm trying to do is save the user's current display mode so that it can be restored later. This is what's messing the whole thing up.

w00t, i'm winning
Offline Jeff

JGO Coder

Got any cats?

« Reply #1 - Posted 2006-06-20 22:03:27 »

Well, first thing is to update your graphcis drivers if you havent donme so lately as this smells like a driver problem.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!
Offline fletchergames

Senior Devvie

« Reply #2 - Posted 2006-06-21 02:19:06 »

Why does your class extend JApplet when your game isn't an applet?  That should be unnecessary.

You have to add a line like
in there somewhere if you want the keyPressed method to ever get called.  KeyListeners have to be registered with the Components they're listening to via the addKeyListener method.

You could try having code like the following at the end of main:

Thread.sleep(5000); //sleep for 5 seconds

That will cause the program to wait for 5 seconds and then exit.  This way, the program will be terminate even without the KeyListener.

What operating system do you have?  You should get a stable operating system such as Windows XP Professional, Windows 2000, or Linux.  Then Alt-Ctrl-Del (or whatever the Linux alternative is) should work.

By the way, since you had to shut off your computer manually while the operating system was still running, you should run ScanDisk (sometimes called CheckDisk) to make sure your hard drive doesn't have any bad sectors.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline bert

Junior Devvie

Miles of road and miles of code

« Reply #3 - Posted 2006-06-21 18:52:40 »

Yeah, I know I kinda need a new machine. I was thinking of buying a laptop and souping it up. Right now I'm running (okay, don't cringe) Windows ME, on an HP Pavilion computer with 383 MB of RAM. The RAM isn't bad but the OS is.  Roll Eyes

Oh, and also I extended JApplet because it's what I'm used to doing. I really don't know much else and JApplet makes it so easy to initialize everything.

w00t, i'm winning
Pages: [1]
  ignore  |  Print  

EgonOlsen (60 views)
2018-06-10 19:43:48

EgonOlsen (42 views)
2018-06-10 19:43:44

EgonOlsen (61 views)
2018-06-10 19:43:20

DesertCoockie (241 views)
2018-05-13 18:23:11

nelsongames (142 views)
2018-04-24 18:15:36

nelsongames (141 views)
2018-04-24 18:14:32

ivj94 (883 views)
2018-03-24 14:47:39

ivj94 (144 views)
2018-03-24 14:46:31

ivj94 (795 views)
2018-03-24 14:43:53

Solater (159 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!