participate


Java Programming [Archive] - how do i change screen resolution
<<   Back to Forum  |   Give us Feedback Topics: « Previous | Next »
5 Duke Stars available
This topic has 4 replies on 1 page.
mlucool
Posts:6
Registered: 1/5/04
how do i change screen resolution   
Jan 5, 2004 4:05 PM

 
i have made a game, and the objects all come out funny (using the gridlayout) when not in 1024x768 how would i change it to that resolution when the user opens the game?
 
venuavula
Posts:9
Registered: 1/5/04
Re: how do i change screen resolution   
Jan 5, 2004 7:27 PM (reply 1 of 4)  (In reply to original post )

 
If u r using swing then u can use the following

JFrame.setSize(new Dimension(d.width,d.height));

I guess this might help!!
 
mlucool
Posts:6
Registered: 1/5/04
Re: how do i change screen resolution   
Jan 5, 2004 8:44 PM (reply 2 of 4)  (In reply to #1 )

 
If u r using swing then u can use the following

JFrame.setSize(new Dimension(d.width,d.height));

I guess this might help!!

i replaced d.width,d.height with 1024, 768 and it didn't do anything

anyone else got an idea
 
Kevin-Pors
Posts:666
Registered: 9/2/03
Re: how do i change screen resolution   
Jan 6, 2004 1:14 AM (reply 3 of 4)  (In reply to #2 )

 
That statement will set the Frame's size to 1024 x 768. If you want to change the screen-resolution of your monitor, the only option I see is to use JNI.
 
760613
Posts:468
Registered: 3/16/01
Re: how do i change screen resolution   
Feb 16, 2004 11:05 AM (reply 4 of 4)  (In reply to #3 )

 
That statement will set the Frame's size to 1024 x
768. If you want to change the screen-resolution of
your monitor, the only option I see is to use JNI.

?????????????

No need for jni here!

And yes you can change to any ( supported ) resolution.

This is a simple demo:
It read the current resolution and opens a new frame (fullscreen) in 1024 x 768.
And later change the resolution back to old one.

import java.awt.Window;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.DisplayMode;
import java.awt.Frame;
 
public class DisplayModeTest0
{
 
    public DisplayModeTest0()
    {
        GraphicsDevice myDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
 
        Frame frame = new Frame();
        Window w = new Window( frame );
        w.setSize(500,500);
        w.setVisible(true);
 
        DisplayMode oldDisplayMode = myDevice.getDisplayMode();
        DisplayMode newDisplayMode = new DisplayMode( 1024,768, 32, 85 );
 
        try
        {
            myDevice.setFullScreenWindow(w);
            myDevice.setDisplayMode(newDisplayMode);
            Thread.sleep(5000);
        }
        catch( Exception e )
        {
            e.printStackTrace();
        }
        finally
        {
            myDevice.setDisplayMode(oldDisplayMode);
            myDevice.setFullScreenWindow(null);
        }
        System.exit(0);
    }
 
 
    public static void main(String[] args)
    {
        DisplayModeTest0 displayModeTest = new DisplayModeTest0();
    }
}



Need more information start read the fullscreen guid:
http://java.sun.com/docs/books/tutorial/extra/fullscreen/index.html

good luck!
 
This topic has 4 replies on 1 page.
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics
    Users Online : 28
  • Guests : 129

About Sun forums
  • Oracle Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Oracle Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums