Question about creating GraphicsEnvironment variable.

0 Mohinish Chatterjee · May 19, 2015
I wrote the same program as u discussed in the video tutorial titled "creating a screen for games". But eclipse shows an error while creating a GraphicsEnvironment variable saying "GraphicsEnvironment.getLocalGraphicsEnvironment cannot be resolved to a type" . I mean i don't understand why? Although i wrote ditto same code as urs, bucky. Plz, need help, i can't resolve this.

Post a Reply

Replies

Oldest  Newest  Rating
+1 Nicholas Eason · May 19, 2015
Do you have java.awt.GraphicsEnvironment imported?
0 Mohinish Chatterjee · May 20, 2015
Yes. I imported java.awt.* . That pretty much includes GraphicsEnvironment. I wrote exactly as was shown in the video. Here i'm inserting the code. 

import java.awt.*;
import javax.swing.JFrame;

public class Screen{

private GraphicsDevice vc;

public Screen(){

GraphicsEnvironment env = new GraphicsEnvironment.getLocalGraphicsEnvironment();

/*here is where the error occurs. It says, "GraphicsEnvironment.getLocalGraphicsEnvironment cannot be resolved to a type"*/

vc=env.getDefaultScreenDevice();
}

public void setFullScreen(DisplayMode dm, JFrame window){

window.setUndecorated(true);
window.setResizable(false);
vc.setFullScreenWindow(window);

if(dm!=null && vc.isDisplayChangeSupported()){
try{
vc.setDisplayMode(dm);
}catch(Exception ex){}
}
}

public Window getFullScreenWindow(){
return vc.getFullScreenWindow();
}

public void restoreScreen(){
Window w=vc.getFullScreenWindow();
if(w!=null)
w.dispose();
vc.setFullScreenWindow(null);
}
}
+1 Nicholas Eason · May 20, 2015
GraphicsEnvironment env = new GraphicsEnvironment.getLocalGraphicsEnvironment();

You aren't getting a new LocalGraphicsEnvironment. Remove the new, that's what your problem is.

GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
0 Mohinish Chatterjee · May 22, 2015
Thanks a ton! It worked :)
  • 1

Java / Android Development

107,182 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator