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 2 of 2

Thread: getX and getY in Visual Studio Code

  1. #1
    Junior Member
    Join Date
    Nov 2019
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default getX and getY in Visual Studio Code

    Hello,

    In the below code I expected frame.getX() be 300 and frame.getY() be 200.
    But in output frame.getX() be 200 and frame.getY() be 300.



    import java.lang.*;
    import java.awt.GraphicsConfiguration;
    import javax.javax.swing.*;
    import javax.swing.JFrame;
     
    public class Main {
    	static GraphicsConfiguration gc;
    	public static void main(String[] args) {
     
    		JFrame frame = new JFrame(gc);
    		frame.setVisible(true);
    		frame.setSize(300,200);
    		frame.setLocation(200, 300);
    		frame.setTitle("PNU");
     
    		System.out.println(frame.getWidth());
    		System.out.println(frame.getX());
    		System.out.printf("__________\n");
    		System.out.println(frame.getHeight());
    		System.out.println(frame.getY());
    	}
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,975
    Thanks
    53
    Thanked 2,444 Times in 2,395 Posts

    Default Re: getX and getY in Visual Studio Code

    The posted code has compiler errors. Please fix.

    error: package javax.javax.swing does not exist

    Also add some text to the printouts giving the names of the values being printed:
    		System.out.println("w="+frame.getWidth());
    		System.out.println("x="+frame.getX());
    		System.out.printf("__________\n");
    		System.out.println("h="+frame.getHeight());
    		System.out.println("Y="+frame.getY());

    Read the API doc for the setLocation method.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. A refugee from Visual Studio ...
    By MontanaMan in forum Member Introductions
    Replies: 3
    Last Post: August 19th, 2019, 01:36 PM
  2. Confused about JPanel.getY()
    By jnewcomer in forum AWT / Java Swing
    Replies: 5
    Last Post: October 31st, 2011, 11:16 AM
  3. Trouble with getX() and getY()
    By mdegges in forum What's Wrong With My Code?
    Replies: 15
    Last Post: July 13th, 2011, 10:48 AM
  4. [SOLVED] mouse getX and getY are off?
    By Brt93yoda in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 6th, 2010, 12:49 AM
  5. java.util.* and visual studio 2005
    By natalie in forum Java Theory & Questions
    Replies: 0
    Last Post: February 26th, 2010, 10:34 AM