import java.awt.Color;
import java.awt.DisplayMode;
import java.awt.Font;

import javax.swing.JFrame;


class GameStation extends JFrame{
    

    public static void main(String [] args){
        
        
        
        DisplayMode dm=new DisplayMode(800, 600, 16, DisplayMode.REFRESH_RATE_UNKNOWN);
        GameStation game=new GameStation();
        game.run(dm);
        
    }

    public void run(DisplayMode dm) {
        setBackground(Color.PINK);
        setForeground(Color.WHITE);
        setFont(new Font("Arial", Font.PLAIN, 24));
    
        Ex7 s=new Ex7();
        try{
            s.setFullScreen(dm, this);
            try{
                 Thread.sleep(5000);    
                }catch(Exception ez){}
        }
                
        finally{
            s.restoreScreen();
        }
    }
}
import java.awt.DisplayMode;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Window;

import javax.swing.JFrame;

class Ex7{
    
    private GraphicsDevice dv;
        
    Ex7(){
        GraphicsEnvironment vc=GraphicsEnvironment.getLocalGraphicsEnvironment();
        dv=vc.getDefaultScreenDevice();
    }
    public void setFullScreen(DisplayMode dm, JFrame j){
        j.setUndecorated(true);
        j.setResizable(false);
        dv.setFullScreenWindow(j);
        
        if(dv!=null && dv.isFullScreenSupported()){
            try{
                dv.setDisplayMode(dm);
            }catch(Exception ex){}
        }
    }
    
    public Window getFullScreenWindow(){
        return dv.getFullScreenWindow();
    }
    
    public void restoreScreen(){
        Window w= dv.getFullScreenWindow();
        if(w!=null){
            w.dispose();
        }
        dv.setDisplayMode(null);
    }
}

why does it tell me that there is no main?

okay, i corrected that mistake..

does anyone know why i get this exception?

Exception in thread "main" java.lang.UnsupportedOperationException: Cannot change display mode
    at java.awt.GraphicsDevice.setDisplayMode(Unknown Source)
    at sun.awt.Win32GraphicsDevice.setDisplayMode(Unknown Source)
    at Screen.restoreScreen(Screen.java:37)
    at GameStation.run(MyDrawPanel.java:33)
    at Image.main(Image.java:17)

at Screen.restoreScreen(Screen.java:37) points to this line: dv.setDisplayMode(null);
According to API:

Throws:
    IllegalArgumentException - if the DisplayMode supplied is null, or is not available in the array returned by getDisplayModes 
    UnsupportedOperationException - if isDisplayChangeSupported returns false

You should get an IllegalArgumentException though, but I think this line is a good place to start debugging.

damn, i am new to swings and game making. could someone tell me whether i misplaced a line? where is the mistake?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.