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 8039263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:31:02+00:00 2026-06-05T03:31:02+00:00

//I am trying to learn how to draw objects in java. I’m getting better

  • 0

//I am trying to learn how to draw objects in java. I’m getting better at it, but once I get an image on the screen I am having trouble manipulating it. The numbers I put in don’t make sense to how the shapes are turning out. At least to me they don’t. In algebra if you increase a number on the x axis it goes to the right and if you increase a number on the y axis it goes up. Thats not whats happening here. Can anyone explain to me how this works? I’m still new to java, so the more explanation and detail the better. I’m trying to take a couple of hours out a day over my summer to learn java and sometimes it gets a little frustrating. Any help is greatly 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-05T03:31:04+00:00Added an answer on June 5, 2026 at 3:31 am

    Here the Co-ordinates start from the TOP LEFT SIDE of the screen, as as you increase value of X, you will move towards RIGHT SIDE, though as you increase the value of Y, you will move DOWNWARDS. Here is a small example Program for you to understand this a bit better, simply click on it anywhere.

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class DrawingExample
    {
        private int x;
        private int y;
        private String text;
        private DrawingBase canvas;
    
        private void displayGUI()
        {
            JFrame frame = new JFrame("Drawing Example");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
            canvas = new DrawingBase();
            canvas.addMouseListener(new MouseAdapter()
            {
                public void mouseClicked(MouseEvent me)
                {
                    text = "X : " + me.getX() + " Y : " + me.getY();
                    x = me.getX();
                    y = me.getY();
                    canvas.setValues(text, x, y);
                }
            }); 
    
            frame.setContentPane(canvas);
            frame.pack();
            frame.setLocationByPlatform(true);
            frame.setVisible(true);
        }
    
        public static void main(String... args)
        {
            SwingUtilities.invokeLater(new Runnable()
            {
                public void run()
                {
                    new DrawingExample().displayGUI();
                }
            });
        }
    }
    
    class DrawingBase extends JPanel
    {
        private String clickedAt = "";
        private int x = 0;
        private int y = 0;
    
        public void setValues(String text, int x, int y)
        {
            clickedAt = text;
            this.x = x;
            this.y = y;
            repaint();
        }
    
        public Dimension getPreferredSize()
        {
            return (new Dimension(500, 400));
        }
    
        public void paintComponent(Graphics g)
        {
            super.paintComponent(g);
            g.drawString(clickedAt, x, y);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

trying to learn windows programming in java, want to display a image to a
I am somewhat new to jQuery but have been having fun trying learn about
Trying to learn F# but got confused when trying to distinguish between fold and
Trying to learn Django, I closed the shell and am getting this problem now
I'm currently trying to learn the ins and outs of XNA/C# but I'm currently
im trying to learn how to use javascript objects, and got some issue here.
I've always worked with Windows Forms, but now I'm trying to learn WPF due
I'm learning android and java and am trying to learn how to make a
I've never used Java for graphics before so I am currently trying to learn.
I'm trying to learn how to draw a shape, and be able to a)

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.