1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Question about setting a value for x

Discussion in 'Software Development' started by OneLuv, Jul 8, 2007.

Thread Status:
Not open for further replies.
  1. OneLuv

    OneLuv Thread Starter

    Joined:
    Dec 28, 2006
    Messages:
    274
    Part of the assignment said set the x and y values of start to 10. The code looked like:

    start.x = 10;
    start.y = 10;

    Can someone tell me why the start (dot) x ? I see in other parts of the code so far I have encountered g (dot)drawString.

    Or point me in the right direction to find out why. I can't remember to do somethings if I don't know why they are done.

    Thanks much:)
     
  2. Shadow2531

    Shadow2531

    Joined:
    Apr 30, 2001
    Messages:
    2,636
    SomeClass.java
    Code:
    public class SomeClass {
        public int x; // public member attribute
        public int y; // public member attribute
    }
    
    TestProgram.java
    Code:
    public class TestProgram {
        public static void main(String[] args) {
            SomeClass start = new SomeClass(); // create an instance 'start' of SomeClass
            start.x = 44; // Set start's public x member (which is an int) to 44
            start.y = 33;
            System.out.println(start.x);
            System.out.println(start.y);
        }
    }
    
    In the case of g.drawString(), g is an instance of the Graphics class and drawString is a member function of the Graphics class. Since you're dealing with the g instance, if you want to call drawString for g, you do g.drawString("string", 5, 5) for example.

    Is that what you mean?
     
  3. WARnux

    WARnux

    Joined:
    Jun 29, 2007
    Messages:
    78
    Learn all about classes.
    Don't worry, it's a very simple concept, you'll get it.
    The . is how you access members of a class.
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/593391

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice