Results 1 to 9 of 9
  1. #1
    jwl
    jwl is offline Member
    Join Date
    Jul 2012
    Posts
    93
    Rep Power
    0

    Default full screen game tutorial issue

    I have been watching a java game development tutorial on youtube to create a full screen display for five seconds

    Here is the first class:

    Java Code:
    package Screen;
    
    import java.awt.*;
    import javax.swing.JFrame;
    
    public class Screen {
        
        private GraphicsDevice vc;
        
        public Screen() {
            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 ex) {}
            }
        }
        
        public Window getFullScreenWindow(){
            return vc.getFullScreenWindow();
                    
        }   
            public void restoreScreen(){
            Window w = vc.getFullScreenWindow();
            if(w != null) {
                w.dispose();
            }
            vc.setFullScreenWindow(null);
        }
    }

  2. #2
    jwl
    jwl is offline Member
    Join Date
    Jul 2012
    Posts
    93
    Rep Power
    0

    Default Re: full screen game tutorial issue

    Here is the second class

    Java Code:
    package Screen;
    
    import java.awt.*;
    import javax.swing.JFrame;
    
    public class bucky extends JFrame {
        public static void main(String[] args){
            
            DisplayMode dm = new DisplayMode(800,600,16, DisplayMode.REFRESH_RATE_UNKNOWN);
            bucky b = new bucky();
            b.run(dm);
        }
        
        public void run(DisplayMode dm) {
            setBackground(Color.PINK);
            setForeground(Color.WHITE);
            setFont (new Font("Arial", Font.PLAIN, 24));
            
            Screen s = new Screen();
            try{
                try{
                    Thread.sleep(25000);
                }catch(Exception ex) {}
            }finally{
                s.restoreScreen();
            }
        }
        
        public void paint(Graphics g) {
            g.drawString("This is going to be awesome", 200, 200);
        }
    }
    My issue is that the screen will not appear but the program runs with no errors.

  3. #3
    SRaith is offline Member
    Join Date
    Oct 2011
    Posts
    14
    Rep Power
    0

    Default Re: full screen game tutorial issue

    First of all, you don't need a new post for every class you have, you can put them all together in just one post.

    I think the problem is, that you never call the method "setFullScreen", which means, you just have
    to call that method after you created the Screen object.

    Java Code:
    s.setFullScreen(dm, this);

  4. #4
    jwl
    jwl is offline Member
    Join Date
    Jul 2012
    Posts
    93
    Rep Power
    0

    Default Re: full screen game tutorial issue

    Quote Originally Posted by SRaith View Post
    I think the problem is, that you never call the method "setFullScreen", which means, you just have
    to call that method after you created the Screen object.

    Java Code:
    s.setFullScreen(dm, this);

    In the tutorial the person says that this:

    Java Code:
    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 ex) {}
            }
        }
    is when you call the "setFullScreen" method and it looks exactly like what he has.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: full screen game tutorial issue

    Stop trying out games and fullscreen stuff and learn the basics first; in this case, the difference between defining a method and invoking it.
    Lesson: Object-Oriented Programming Concepts (The Java™ Tutorials > Learning the Java Language)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    jwl
    jwl is offline Member
    Join Date
    Jul 2012
    Posts
    93
    Rep Power
    0

    Default Re: full screen game tutorial issue

    Quote Originally Posted by DarrylBurke View Post
    Stop trying out games and fullscreen stuff and learn the basics first; in this case, the difference between defining a method and invoking it.
    Lesson: Object-Oriented Programming Concepts (The Java™ Tutorials > Learning the Java Language)

    db
    Thank you for your input.

    Correct me if I'm wrong but I believe my error in the previous post was stating that the wrong method is the method which calls the the FullScreen application.
    I believe that this is the method which calls the FullScreen:

    Java Code:
      
        public Window getFullScreenWindow(){
            return vc.getFullScreenWindow();
                     
        }
    Back to the original question. Is there a reason why this code will not display a full screen window with a pink background and white text? If you copy and paste it in your IDE does it work on your computer? Here is a link to my source if you do not trust my code. Java Game Development Tutorials - YouTube

  7. #7
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    2

    Default Re: full screen game tutorial issue

    Quote Originally Posted by jwl View Post
    Thank you for your input.

    Correct me if I'm wrong but I believe my error in the previous post was stating that the wrong method is the method which calls the the FullScreen application.
    I believe that this is the method which calls the FullScreen:

    Java Code:
      
        public Window getFullScreenWindow(){
            return vc.getFullScreenWindow();
                     
        }
    Back to the original question. Is there a reason why this code will not display a full screen window with a pink background and white text? If you copy and paste it in your IDE does it work on your computer? Here is a link to my source if you do not trust my code. Java Game Development Tutorials - YouTube
    In your run() method of class bucky, you don't invoke the setFullScreenWindow() method nor the getFullScreenWindow() method. What you posted is the definition of getFullScreenWindow(), not the invocation of it. Are you sure you understand the difference?

    If not, that's the place to start (as db suggested).
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  8. #8
    jwl
    jwl is offline Member
    Join Date
    Jul 2012
    Posts
    93
    Rep Power
    0

    Default Re: full screen game tutorial issue

    Quote Originally Posted by SRaith View Post
    First of all, you don't need a new post for every class you have, you can put them all together in just one post.

    I think the problem is, that you never call the method "setFullScreen", which means, you just have
    to call that method after you created the Screen object.

    Java Code:
    s.setFullScreen(dm, this);
    I totally missed that. it worked After I added that line of code.

  9. #9
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    2

    Default Re: full screen game tutorial issue

    Quote Originally Posted by jwl View Post
    I totally missed that. it worked After I added that line of code.
    But do you understand why it works?
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

Similar Threads

  1. Full Screen window over toolbar
    By vmcg in forum AWT / Swing
    Replies: 3
    Last Post: 07-10-2010, 03:43 AM
  2. Full screen problems
    By doctorned in forum New To Java
    Replies: 4
    Last Post: 12-10-2009, 09:40 AM
  3. Full screen test
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-23-2008, 11:24 PM
  4. how to set full screen dimensions
    By valery in forum New To Java
    Replies: 1
    Last Post: 08-03-2007, 06:08 PM
  5. Full screen
    By Jack in forum Advanced Java
    Replies: 2
    Last Post: 07-02-2007, 05:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •