Results 1 to 6 of 6

Thread: How to get screen resolution using java program?

  1. #1
    Join Date
    Nov 2009
    Posts
    50

    How to get screen resolution using java program?

    Hi friends,
    I am new to this forum. I am working on live project where I use Java as front end. In this program I have to show screen resolution. I tried various methods but none of them worked out. Can anyone tell me how to get screen resolution using java program? Please help me.
    Thanks in advanced.
    Last edited by Luz; 03-02-2010 at 08:21 PM.

  2. #2
    Join Date
    Nov 2005
    Posts
    1,323

    Re: How to get screen resolution using java program?

    Hey it is very simple program. You have to just use java.awt.Dimension class to show screen resolution. First import this class in your program and then import java.awt.Toolkit class. In following program I have use ScreenSizeExample class and "ss" as one dimension.



    Code:
    package org.kodejava.example.java.awt;
    
    import java.awt.Dimension;
    import java.awt.Toolkit;
    
    public class ScreenSizeExample {
        public static void main(String[] args)
        {
            Dimension ss = Toolkit.getDefaultToolkit().getScreenSize();
            
            System.out.println("Screen Widht: " + ss.getWidth());
            System.out.println("Screen Height: " + ss.getHeight());
        }
    }

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    Re: How to get screen resolution using java program?

    Hey there is no need to write whole program to get screen resolution. You have to just use following code to do this. Just paste following code in your program and run your program.

    <script type="text/javascript">
    document.write(screen.width+'x'+screen.height);
    </script>


    Above code is written in jsp. Just include this code in your project to get screen resolution.

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: How to get screen resolution using java program?

    You have to perform two process to do this. Just use following two steps.

    Step 1 : First use following code in your page. This step is used to get visitor's screen resolution.
    Code:
    <script types="texts/javascripts">
    documents.writes(screens.widths+'y'+screen.height);
    </script>
    step 2: After getting visitor's screen resolution you have to redirect them to a particular page. For this you have to use following code.

    Code:
    <script types="texst/javascript">
    if ((screens.width<=1024) && (screens.height<=786)) {
     windows.locations.replaces('http://EG.com/1024-786-or-less');
    }
    else {
       windows.locationss.replace('http://Eg.com/greater-than-1024-786');
    }
    </script>

  5. #5
    Join Date
    Feb 2008
    Posts
    1,852

    Re: How to get screen resolution using java program?

    Using following program you will able to learn how to obtain the height and width of the specific screen using java program. It is very simple program. You have to use getDefaultToolkit() to obtain the default Toolkit object of the users screen. I have written following program for you. Just try to understand it.

    Code:
    import java.awt.*;
    public class GetScreenResolution
    {
      public static void main(String[] args){
        Toolkit toolkitsw =  Toolkitsw.getDefaultToolkit ();
            Dimension dimsw = toolkitsw.getScreenSize();
        System.out.println("Screen Width  "+dimsw.width+"in pixels");
        System.out.println(" Screen Height  "+dimsw.height+"in  pixels");
      }
    }

  6. #6
    Join Date
    Jan 2008
    Posts
    1,521

    Re: How to get screen resolution using java program?

    If you use JSP then it will easy for you to get screen resolution. You have to just use simple code in your program to do this. Just look at following code.

    Code:
    <script languagees="javascriptws">
    <!--
    documenswt.writesw('<psw> +screenws.width+ ' x ' +screenws.height+ '</psw>');
    //-->
    </script>
    Just add this code in your jsp page.

Similar Threads

  1. Dr. Java program
    By bamggut29 in forum Software Development
    Replies: 2
    Last Post: 26-11-2011, 04:24 AM
  2. Need help to write this program in java?
    By frkadeel in forum Software Development
    Replies: 1
    Last Post: 01-12-2010, 03:58 PM
  3. Java program to center a JFrame on screen
    By KALANI84 in forum Software Development
    Replies: 5
    Last Post: 13-02-2010, 05:48 PM
  4. Java - resolution of f (x) = 0
    By Caden Fernandes in forum Software Development
    Replies: 5
    Last Post: 08-01-2010, 10:55 AM
  5. Link List Example in Java Sample program in Java
    By trickson in forum Software Development
    Replies: 2
    Last Post: 04-08-2009, 08:23 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,724,339.95602 seconds with 17 queries