Results 1 to 6 of 6
Thread: So Lost
- 12-13-2008, 01:15 AM #1
Member
- Join Date
- Nov 2008
- Posts
- 5
- Rep Power
- 0
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.
- 12-13-2008, 01:32 AM #2
#### 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.
- 12-13-2008, 01:38 AM #3
Member
- Join Date
- Nov 2008
- Posts
- 5
- Rep Power
- 0
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.
-
You may be getting slightly ahead of yourself here with this project. Why not start learning the basics?
- 12-13-2008, 07:12 AM #5
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.
- 12-13-2008, 09:55 PM #6
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.
That's 570 lines in a manual text editor - no ide - just to have a core to build around,....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. */
Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Similar Threads
-
need help with program im lost
By lifeturn in forum JCreatorReplies: 1Last Post: 10-28-2008, 07:09 PM -
Has Java lost its way?
By alexj44 in forum Advanced JavaReplies: 4Last Post: 09-23-2008, 01:26 PM -
Lost my javadocs
By orchid in forum EclipseReplies: 3Last Post: 04-30-2008, 09:45 PM -
Absolutely Lost
By Lehane_9 in forum New To JavaReplies: 2Last Post: 12-03-2007, 06:25 PM -
Help Needed - I'm so lost
By adlb1300 in forum New To JavaReplies: 3Last Post: 11-14-2007, 01:54 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks