Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8021675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:03:18+00:00 2026-06-04T22:03:18+00:00

I am a beginner who is learning to write games in JAVA. In the

  • 0

I am a beginner who is learning to write games in JAVA.

In the game I am writing, I am trying to get it to support multiple displayModes. First let me tell you a little about how I’m setting the display setting in the first place.

In the beginning of the code, I have an list of display modes I wish to support

//List of supported display modes
private static DisplayMode modes[] = {
    new DisplayMode(640, 480, 32, 0),
    new DisplayMode(1024, 768, 32, 0),
}; 

I then get a list of supported display Modes from the Video Card, comparing the list and use the first matching display mode.

/////////////////////////////////////////////
////Variable Declaration
/////////////////////////////////////////////
private GraphicsDevice vc;

/////////////////////////////////////////////   
//Give Video Card Access to Monitor Screen
/////////////////////////////////////////////
public ScreenManager(){
    GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
    vc = e.getDefaultScreenDevice();
}
/////////////////////////////////////////////
//Find Compatible display mode
/////////////////////////////////////////////
//Compare Display mode supported by the application and display modes supported by the video card
//Use the first matching display mode;
public DisplayMode findFirstCompatibleMode(DisplayMode modes[]){
    DisplayMode goodModes[] = vc.getDisplayModes();
    for(int x=0; x<modes.length; x++){
        for(int y=0; y<goodModes.length; y++){
            if (displayModesMatch(modes[x], goodModes[y])){
                return modes[x];
            }
        }
    }
    return null;
}

/////////////////////////////////////////////   
//Checks if two Display Modes match each other
/////////////////////////////////////////////
public boolean displayModesMatch(DisplayMode m1, DisplayMode m2){

    //Test Resolution
    if (m1.getWidth() != m2.getWidth() || m1.getHeight() != m2.getHeight()){
        return false;
    }

    //Test BitDepth
    if (m1.getBitDepth() != DisplayMode.BIT_DEPTH_MULTI && m2.getBitDepth() != DisplayMode.BIT_DEPTH_MULTI
            && m1.getBitDepth() != m2.getBitDepth()){
        return false;
    }

    //Test Refresh Rate
    if (m1.getRefreshRate() != DisplayMode.REFRESH_RATE_UNKNOWN &&
            m2.getRefreshRate() != DisplayMode.REFRESH_RATE_UNKNOWN &&
            m1.getRefreshRate() != m2.getRefreshRate()){
        return false;
    }

    return true;
}

Currently, I am only supporting two resolutions, 640×480 and 1024×768.

In order to have every element of my game available in both resolutions, first I find how much the screen is resized and store this value in a variable called resizeRatio

private void getResizeRatio(){
    resizeRatio = (double)1024/(double)s.getWidth();
    //s.getWidth() returns the current width of the screen.
}

And with every image I import, i would divide the image height and width by this resizeRatio.

/////////////////////////////////////////////
//Scale the image to the right proportion for the resolution
/////////////////////////////////////////////
protected Image scaleImage(Image in){
    Image out = in.getScaledInstance((int)(in.getWidth(null)/resizeRatio), (int)(in.getHeight(null)/resizeRatio), Image.SCALE_SMOOTH);
    return out;
}

This is all fine and good, until my application grew bigger and bigger. Soon I realize I forgot to resize some of the icons, and they are all at the wrong place when resolution is 640×480.

Additionally, I realize I must scale, not just the size of all my images, but all the movement speed, and all the positions as well, since having my character move at 5px per refresh makes him move significantly faster when displayed at 640×480 than when displayed at 1024×768

So my question is, instead of individually scaling every image, every icon, and every movement, is there a way to scale everything all at once? Or rather, there must be another way of doing this so could someone please tell me?

Thank you for reading and any help would be much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T22:03:19+00:00Added an answer on June 4, 2026 at 10:03 pm

    In the paintComponent(Graphics g) or paint method you can do with Graphics2D.scale:

    private double scale = 0.75;
    
    @override
    public void paintComponent(Graphics g) {
        Graphics2D g2 = (Graphics2D)g; // The newer more ellaborate child class.
        g2.scale(scale, scale);
        ...
        g2.scale(1/scale, 1/scale);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a C++ program that works like the game 24.
I am just a beginner who is trying to play around with QR codes.
Java beginner here who is terribly confused as to why 1) this is valid
Background: I am a beginner javascript developer who is trying to understand and learn
Hi i am a beginner who is learning Python, i have stumbled across this
I'm a beginner android programmer who is trying to set up some USB functionality
Could someone please help me in here, I'm just a beginner who want to
PHP beginner working from a tutorial. I'm trying to do a simple upload from
Am Beginner to java.I have a small doubt while i am developing an application
I'm a beginner to intermediate programmer and I've learned some java and C#. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.