Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: How to activate fullscreen in a different class?

  1. #1
    Member
    Join Date
    Oct 2011
    Posts
    37
    My Mood
    Where
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to activate fullscreen in a different class?

    I am trying to get a simple fullscreen window for a game I am making. I want to have the code that makes the window go fullscreen in a different class to my main class (called FullScreenWindow), but have the main class activate the fullscreen mode. The code that makes the window fullscreen in in the 'Screen' class.

    Here is the code for the Screen class:
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Font;
    import java.awt.GraphicsDevice;
    import java.awt.GraphicsEnvironment;
     
    import javax.swing.JFrame;
    import javax.swing.JLabel;
     
    @SuppressWarnings("serial")
    public class Screen extends JFrame{
     
      public Screen( String title )
      {
          super(title);
     
          this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
     
          FullScreenWindow frame = new FullScreenWindow();
          frame.setVisible(true);
     
          GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
     
          setUndecorated(true);
          if (gd.isFullScreenSupported()) {
              setUndecorated(true);
              gd.setFullScreenWindow(this);
          } else {
              System.err.println("Full screen not supported");
              setSize(100, 100); // just something to let you see the window
              setVisible(true);
          }
          getContentPane().add(new JLabel("Test Fullscreen"), BorderLayout.NORTH);
          setBackground(Color.BLUE);
          setForeground(Color.WHITE);
          setFont(new Font("Arial", Font.PLAIN, 24));
          drawString("This is cool", 200, 200);
          if(isVisible() == true){
        	  try{
        		  try {
    				Thread.sleep(5000);
    			} catch (Exception ex) {
    				ex.printStackTrace();
    			}
        	  }finally{
        		  Screen.this.setVisible(false);
                  System.exit(0);
        	  }
          }
      }
     
    private void drawString(String string, int i, int j) {
    	// TODO Auto-generated method stub
     
    }
    }

    Here is the code in my FullScreenWindow class (my main class)

    import java.awt.*;
    import javax.swing.*;
    @SuppressWarnings("serial")
    public class FullScreenWindow extends JFrame {
    	public static void main(String[] args){
     
    	}
    }

    I hope you can help.
    Last edited by JamEngulfer221; November 1st, 2011 at 02:36 AM.


  2. #2
    Member
    Join Date
    Oct 2011
    Posts
    37
    My Mood
    Where
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to activate fullscreen in a different class?

    If you need clarification, just ask

  3. #3
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: How to activate fullscreen in a different class?

    Why are either of those classes extending JFrame? They don't override any of the default behavior. Favor composition over inheritance, and I think it will make more sense what you have to do.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  4. #4
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Re: How to activate fullscreen in a different class?

    lol...

    try this man:

                // Get the size of the screen
    	    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();

    once you have the size of the screen simply set the height and width of the game frame to width and height that dim is equal to.
    Last edited by macko; November 1st, 2011 at 08:37 AM.

  5. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: How to activate fullscreen in a different class?

    Quote Originally Posted by macko View Post
    lol...

    try this man:

                // Get the size of the screen
    	    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();

    once you have the size of the screen simply set the height and width of the game frame to width and height that dim is equal to.
    Not only is that not the correct way to use a fullscreen JFrame, that doesn't answer the OP's actual question. Please read this before posting again: http://www.javaprogrammingforums.com...n-feeding.html
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #6
    Member
    Join Date
    Oct 2011
    Posts
    37
    My Mood
    Where
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to activate fullscreen in a different class?

    Just a note, all of my CODE that makes it fullscreen works, just, it won't ACTIVATE. If this is something wrong with my code, I feel like an idiot.

    I just need to know how I would activate fullscreen from my main class, on startup of the program.

    I was wondering if a IF statement around the code in Screen class would work.
    Last edited by JamEngulfer221; November 1st, 2011 at 12:21 PM.

  7. #7
    Member
    Join Date
    Oct 2011
    Posts
    37
    My Mood
    Where
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to activate fullscreen in a different class?

    I had done all of this code in the FullScreenWindow class, but I didn't want the code in my main class, so I moved it over to the Screen class.

  8. #8
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: How to activate fullscreen in a different class?

    Again, I'm not sure why you're extending JFrame at all. That's making things more confusing than they have to be.

    Because all you need to do is create an instance of your Screen class (which contains, not extends, a JFrame). Then from the FullScreenWindow class, you can either get that instance's JFrame and make it fullscreen, or you can call a method that does it for you in the Screen class.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. I need help with my FullScreen Code
    By JamEngulfer221 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 31st, 2011, 06:21 AM
  2. Applet and Fullscreen !!
    By rt4ever in forum Java Applets
    Replies: 21
    Last Post: September 5th, 2011, 07:43 PM
  3. Help requested - testing a class with a tester class, no methods allowed.
    By miketeezie in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 21st, 2011, 10:40 PM
  4. FullScreen isn't working in Win 7
    By Ahmed.Ibrahem in forum AWT / Java Swing
    Replies: 0
    Last Post: February 6th, 2011, 11:48 AM
  5. Getting a TextField to activate ItemListener.
    By javapenguin in forum AWT / Java Swing
    Replies: 5
    Last Post: July 20th, 2010, 11:07 PM