Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By JosAH

Thread: questions on Jframe cordinate system and aspect ratio handeling

  1. #1
    Join Date
    Dec 2014
    Rep Power

    Default questions on Jframe cordinate system and aspect ratio handeling

    hello guys! I've got a game, and in that game I have pngs and Jpegs and all that jazz.

    Now when these guys are put up on screen , they are scaled to the aspect ration of the computer I am working on currently. EX:

    buffergraphics.drawImage(image,xcord,ycord, 50, 50, null);

    course on some other screens, this may look really weird.

    so , given that the Dimensions method thingy will get you the size of the current window you can find the aspect ratio and adjust.

    so if the original window (they way I want it to look) Was 1000x1000 and the new window is 1000x500 I can simply go :

    Dimensions current = new Dimensions(); (whatever the line is, pseudo code man!)

    double Yratio = current.y/1000 (original Y value) ; // this is equal to 500/1000 which = 0.5
    double Xratio = current.x / 1000 (orginal X value) ; // this is equal to 1000/100 which = 1.0

    buffergraphics.drawImage(image,xcord,ycord, 50 * Yratio, 50 * Xratio, null);

    now here is my questions

    a) does this work? can the Jframe system take doubles? if the ratio was persay 0.324 and the output 22.58, will it round it? take it? crash?
    b) Should I use this ratio system? which will allow any aspect ratio as the user drags the window larger or smaller, or should I use a preset group of ratios which can be selected? (Like a video game)

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power

    Default Re: questions on Jframe cordinate system and aspect ratio handeling

    A JFrame doesn't draw anything; it's a container with a border, title line and a few buttons in the top right corner; it uses a content pane that does the drawing stuff (it's a JComponent). You can (and often have to) override its paintComponent( ... ) method that uses a Graphics object that can do the actual drawing; to complicate matters even further, such a Graphics object actually is a Graphics2D object that can scale whatever it has to draw. Read the API documentation for the Graphics2D class and see how it can handle scaling.

    kind regards,

    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Replies: 1
    Last Post: 06-29-2013, 07:06 PM
  2. JFrame questions
    By phantomcraft in forum New To Java
    Replies: 2
    Last Post: 02-26-2013, 04:18 PM
  3. Replies: 2
    Last Post: 02-21-2011, 11:25 AM
  4. How to set the JFrame to System resolution
    By usha in forum AWT / Swing
    Replies: 4
    Last Post: 10-20-2010, 02:05 PM
  5. [SOLVED] Dynamic String -> Date Handeling
    By vagetoanima in forum Advanced Java
    Replies: 2
    Last Post: 03-31-2009, 06:43 PM

Posting Permissions

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