JAVA GAME DEVELOPMENT

0 Ashutosh Mohanty · March 29, 2015
catch statement is running while using setDisplayMode()....how to fix it...

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

public class ashu{
private GraphicsDevice vc;

public ashu()
{
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
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 e){
System.out.println("kuch toh gadbad h");
}
}
}

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


public void restore(){
Window w = vc.getFullScreenWindow();
if(w != null){
w.dispose();
}
vc.setFullScreenWindow(null);
}



}



import java.awt.*;

import javax.swing.JFrame;
public class screen extends JFrame{
public static void main(String[] args){
DisplayMode dm = new DisplayMode(800,600,16,DisplayMode.REFRESH_RATE_UNKNOWN);
screen s = new screen();
s.run(dm);

}
public void run(DisplayMode dm){
setBackground(Color.PINK);
setForeground(Color.WHITE);
setFont(new Font("Arial", Font.BOLD, 22));
ashu a = new ashu();
try{
a.setFullScreen(dm, this);
try{
Thread.sleep(5000);
}catch(Exception e){
System.out.println("dnt know whats happening");
}
}catch(Exception e){
System.out.println("something is wrong");
}
finally{
a.restore();
}
}
public void paint(Graphics g){
g.drawString("This is the Full Screen", 200, 200);
}
}

Post a Reply

Replies

Oldest  Newest  Rating
0 Nicholas Eason · March 30, 2015
Remove System.out.println(""); and change it to e.printStackTrace(); That way you actually get told what your error is other than "Something is wrong"
0 Ashutosh Mohanty · March 31, 2015
I have Passed all arguments corrects....so why this unknown source error can u help it

java.lang.IllegalArgumentException: Invalid display mode
at sun.awt.Win32GraphicsDevice.setDisplayMode(Unknown Source)
at test.setFullScreen(test.java:17)
at ashu2.run(ashu2.java:20)
at ashu2.main(ashu2.java:9)
0 Nicholas Eason · April 2, 2015
You don't provide a class named ashu2, nor do you provide a class called test. The error is in those two classes.

In case you didn't know, the stack trace has a format.

at CLASS.MEHTOD(CLASS.java:LINE ERROR OCCURRED ON)

i.e

at your class ashu2, in the method run, at line 20 is where the error occurs.
  • 1

Java / Android Development

106,911 followers
About

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

Links
Moderators
Bucky Roberts Administrator