Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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 1339 times)
0 Members and 1 Guest are viewing this topic.
Offline bert

Junior Member




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){
      screen.setDisplayMode(originalMode);
      screen.setFullScreenWindow(null);
      System.exit(0);
   }
   public void keyReleased(KeyEvent e){}
   public void keyTyped(KeyEvent e){}
   public void init(){
      buff=createImage(this.getSize().width,this.getSize().height);
      backg=buff.getGraphics();
      setFocusable(true);
   }
   public void paint(Graphics g){
      mainmenu.paintIcon(this,g,0,0);
   }
   public static void main(String[] args){
      gfxenv=GraphicsEnvironment.getLocalGraphicsEnvironment();
      screen=gfxenv.getDefaultScreenDevice();
      JFrame frame=new JFrame("My Supercool Game");
      frame.setUndecorated(true);
      frame.setResizable(false);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      originalMode=screen.getDisplayMode();   //****** this line gives me problems as well
      if(args.length>0&&args[0].equals("window")) forceWindow=true;
      if(screen.isFullScreenSupported()&&screen.isDisplayChangeSupported()&&!forceWindow){
         screen.setFullScreenWindow(frame);
      }
      else{
         frame.setUndecorated(false);
         frame.setSize(1024,768);
         Insets i=frame.getInsets();
         frame.setSize(i.left+1024+i.right,i.top+768+i.bottom);
      }
      Game g=new Game();
      frame.getContentPane().add(g);
      frame.show();
      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(Game.java:35)

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!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline fletchergames

Senior Member





« 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
1  
frame.addKeyListener(game);
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:

1  
2  
Thread.sleep(5000); //sleep for 5 seconds
System.exit();


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 Member




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  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (28 views)
2014-09-12 09:08:26

Norakomi (57 views)
2014-09-10 13:57:51

TehJavaDev (74 views)
2014-09-10 06:39:09

Tekkerue (38 views)
2014-09-09 02:24:56

mitcheeb (57 views)
2014-09-08 06:06:29

BurntPizza (45 views)
2014-09-07 01:13:42

Longarmx (28 views)
2014-09-07 01:12:14

Longarmx (34 views)
2014-09-07 01:11:22

Longarmx (34 views)
2014-09-07 01:10:19

mitcheeb (40 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!