Results 1 to 6 of 6

Thread: So Lost

  1. #1
    kandt is offline Member
    Join Date
    Nov 2008
    Posts
    5
    Rep Power
    0

    Default So Lost

    I'm writing code straight from a book, so that after it's all done I can go in and try and understand how it works and change it to suit my purposes, but for some reason the code doesn't work and I have no idea why.

    Here's the code:

    import java.awt.*;

    class GraphicsDisp
    {

    GraphicsEnvironment gfxEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice defaultDevice = gfxEnv.getDefaultScreenDevice();
    DisplayMode[] displayModes = defaultDevice.getDisplayModes();
    DisplayMode[] requestedDisplayModes = new DisplayMode[]
    {
    new DisplayMode(1280, 1024, 32, DisplayMode.REFRESH_RATE_UNKNOWN),
    new DisplayMode(1024, 768, 32, DisplayMode.REFRESH_RATE_UNKNOWN),
    new DisplayMode(800, 600, 16, DisplayMode.REFRESH_RATE_UNKNOWN),
    new DisplayMode(640, 480, 16, DisplayMode.REFRESH_RATE_UNKNOWN)
    };

    public static DisplayMode findRequestedMode()
    {
    DisplayMode best = null;
    //loop through all requested modes
    for (int rIndex = 0; rIndex #### requestedDisplayModes.length; rIndex++)
    {
    for (int mIndex = 0; mIndex #### displayModes.length; mIndex++)
    {
    if(displayModes[mIndex].getWidth() ==
    requestedDisplayModes[rIndex].getWidth()
    &&
    displayModes[mIndex].getHeight()
    == requestedDisplayModes[rIndex].getHeight()
    &&
    displayModes[mIndex].getBitDepth() ==
    requestedDisplayModes[rIndex].getBitDepth()){
    //found a match
    if(best == null)
    {
    //if refresh rate was spec'd try to match that as well
    if (requestedDisplayModes[rIndex].getRefreshRate() !=
    DisplayMode.REFRESH_RATE_UNKNOWN)
    {
    if (displayModes[mIndex].getRefreshRate() $$$$=
    requestedDisplayModes[rIndex].getRefreshRate())
    {
    best = displayModes[mIndex];
    return best;
    }
    }
    else
    {
    best = displayModes[mIndex];
    return best;
    }
    }
    }
    }
    }
    //no matching mode so return null
    return best;
    }



    }

    I get errors for "; expected", ") expected", "not a statement" and "illegal character \35" everywhere a # sign is. I know that the # is associated with \35, but I don't know why it's illegal. Do I need to replace the ####'s with the resolutions listed in above the findRequestedMode() Method? Why do I need to add ';'s and a ')'? I can't find anything wrong with this code.

  2. #2
    roots's Avatar
    roots is offline Moderator
    Join Date
    Jan 2008
    Location
    Dallas
    Posts
    293
    Rep Power
    7

    Default

    #### and $$$$$ are not operator .. and you are using them as some sort of comparison operator.

    Is this the one you are looking for ??
    Java Code:
    import java.awt.DisplayMode;
    import java.awt.GraphicsDevice;
    import java.awt.GraphicsEnvironment;
    
    class GraphicsDisp{
    
    	static GraphicsEnvironment	gfxEnv					= GraphicsEnvironment.getLocalGraphicsEnvironment();
    	static GraphicsDevice		defaultDevice			= gfxEnv.getDefaultScreenDevice();
    	static DisplayMode[]		displayModes			= defaultDevice.getDisplayModes();
    	static DisplayMode[]		requestedDisplayModes	= new DisplayMode[] { new DisplayMode(1280, 1024, 32, DisplayMode.REFRESH_RATE_UNKNOWN), new DisplayMode(1024, 768, 32, DisplayMode.REFRESH_RATE_UNKNOWN), new DisplayMode(800, 600, 16, DisplayMode.REFRESH_RATE_UNKNOWN),
    			new DisplayMode(640, 480, 16, DisplayMode.REFRESH_RATE_UNKNOWN) };
    
    	public static DisplayMode findRequestedMode() {
    		DisplayMode best = null;
    		// loop through all requested modes
    		for (int rIndex = 0; rIndex < requestedDisplayModes.length; rIndex++) {
    			for (int mIndex = 0; mIndex < displayModes.length; mIndex++) {
    				if (displayModes[mIndex].getWidth() == requestedDisplayModes[rIndex].getWidth() && displayModes[mIndex].getHeight() == requestedDisplayModes[rIndex].getHeight() && displayModes[mIndex].getBitDepth() == requestedDisplayModes[rIndex].getBitDepth()) {
    					// found a match
    					if (best == null) {
    						// if refresh rate was spec'd try to match that as well
    						if (requestedDisplayModes[rIndex].getRefreshRate() != DisplayMode.REFRESH_RATE_UNKNOWN) {
    							if (displayModes[mIndex].getRefreshRate() >= requestedDisplayModes[rIndex].getRefreshRate()) {
    								best = displayModes[mIndex];
    								return best;
    							}
    						} else {
    							best = displayModes[mIndex];
    							return best;
    						}
    					}
    				}
    			}
    		}
    		// no matching mode so return null
    		return best;
    	}
    }
    dont worry newbie, we got you covered.

  3. #3
    kandt is offline Member
    Join Date
    Nov 2008
    Posts
    5
    Rep Power
    0

    Default

    thank you so much. idk why they would put that in a beginners book and not say anywhere preceding it that #### and $$$$ stand for operators. i've read it from front to the page with the code on it and there's no mention at all, lol. thanks.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    You may be getting slightly ahead of yourself here with this project. Why not start learning the basics?

  5. #5
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    6

    Default

    Yes, do the first example in the book, usually Hello World.
    Work your way through the examples. It will only take a day or two and will save a lot of questions and confusion.

  6. #6
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    7

    Wink 570 core

    They put those things in books so you will have to keep buying books, my first program in Java does things the books will tell you cannot be done.
    Java Code:
    /**
     * We need a class which enables ######### to discuss matters of consequence
     * in the long term planning of our actions.  It is noted for the reader
     * that the casual intruder  will examine only the first and last few bytes
     * of a keystring when browsing for casual reasons.
     */
    That's 570 lines in a manual text editor - no ide - just to have a core to build around,....
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

Similar Threads

  1. need help with program im lost
    By lifeturn in forum JCreator
    Replies: 1
    Last Post: 10-28-2008, 07:09 PM
  2. Has Java lost its way?
    By alexj44 in forum Advanced Java
    Replies: 4
    Last Post: 09-23-2008, 01:26 PM
  3. Lost my javadocs
    By orchid in forum Eclipse
    Replies: 3
    Last Post: 04-30-2008, 09:45 PM
  4. Absolutely Lost
    By Lehane_9 in forum New To Java
    Replies: 2
    Last Post: 12-03-2007, 06:25 PM
  5. Help Needed - I'm so lost
    By adlb1300 in forum New To Java
    Replies: 3
    Last Post: 11-14-2007, 01:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •