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..

JAVA

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

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

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

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

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

        System.out.println("set undecorated and resizable");
        this.setUndecorated(true);  
        this.setResizable(false);

        System.out.println("GraphicsEnvironment\nGraphicsDevice");
        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");
        device.setFullScreenWindow(this);     

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

    public void changeBackground()
    {
        System.out.println("in changeBackground()\nChanging background, foreground and font");        
        this.getContentPane().setBackground(Color.BLUE);
        setForeground(Color.RED);
        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)");
        super.paint(g);  

        System.out.println("anti-aliasing");
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(    
                    RenderingHints.KEY_TEXT_ANTIALIASING,
                    RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

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

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

Recommended Answers

All 4 Replies

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();
    }
}

can anyone help?

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.