Hey, this is my first post, and i'm a complete noob at Java. (i don't exactly know if i did the 'code tags' correctly, so if it didn't work properly, just know that I tried.

my basic question is this: I'm trying to make a program that runs fullscreen on a computer, and prints to the screen. I just printed some random garbage so far for a test.

(note, this code doesn't terminate, so use alt-f4 or some other means.) I removed much of the other code because I noticed the code doesn't always execute properly. and even when i properly terminated the program, it still had this problem. I added some code for the console to tell me where the program is executing at a certain time, but its always in a different order..


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

public class FullScreen extends JFrame
    static GraphicsDevice device;
    private Image opaque;

        System.out.println("In FullScreen constructor");
        System.out.println("Entering setFullScreen()");

        System.out.println("Entering changeBackground()");

    public void setFullScreen() 
        System.out.println("In setFullScreen() Method");

        System.out.println("set undecorated and resizable");

        GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
        device = environment.getDefaultScreenDevice();             

        System.out.println("Finding screen information");
        int x = device.getDisplayMode().getWidth();   
        int y = device.getDisplayMode().getHeight();  
        int bitDepth = device.getDisplayMode().getBitDepth();  
        int refreshRate = device.getDisplayMode().getRefreshRate();           

        System.out.println("Enters screen information");
        DisplayMode displayMode = new DisplayMode(x, y, bitDepth, refreshRate);

        System.out.println("Set full screen");

        if(displayMode != null && device.isDisplayChangeSupported())
                System.out.println("Change display mode");
            catch(IllegalArgumentException e)
                System.err.println("IllegalArgumentException caught");

    public void changeBackground()
        System.out.println("in changeBackground()\nChanging background, foreground and font");        
        this.setFont(new Font("Dialog", 0, 250));        

    public void closeFullScreen()
        device.setFullScreenWindow(null);    //Used to switch back            
        System.exit(0);   //terminates JVM

    public void paint(Graphics g) 
        System.out.println("in Paint method()");
        System.out.println("calling super.paint(g)");

        Graphics2D g2 = (Graphics2D)g;

        System.out.println("drawing shapes");
        g.drawString("FullScreen", 150, 870);
        g.fill3DRect(500, 420, 150, 200, true); 
        g.fillOval(900, 250, 500, 50);  

        System.out.println("shapes drawn");

What exactly is your question?

How do you run the class above when it doesn't have a main?

BTW, your code tags worked perfectly.

I have a main method that just creates an object for "FullScreen" which calls the constructor which calls the methods..

my question is why doesn't it execute properly. It works, but only sometimes, the drawing portion of it. It always runs a fullscreen with the changed background color, but only half the time does it actually draw the shapes.

Also, why does it execute in a different order almost every time?

If absolutely necessary, this is my main method:

public class Main
    public static void main(String[] args)
        FullScreen FS = new FullScreen();