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

Thread: easy prob, just not for me

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Posts
    15
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post easy prob, just not for me

    Hey you ever have that brain fart moment where no matter how long you look at something it won't come? Well that is me now, I am a pretty inexperienced noob to java so please spare the possible dumbness of my question.

    I am just trying to do a basic GRect and fill it so it is black. The line even shows up with no errors. Not sure if I need the whole thing but it is pretty small.


    import acm.graphics.*;
    import acm.program.*;
    import java.awt.*;

    public class Target extends GraphicsProgram {
    public void run() {

    GRect Square = new GRect(100,100,50,50);
    Square.setColor(Color.BLACK);
    Square.setFillColor(Color.BLACK);
    add(Square);


    }


    }


    Thanks in advance, I am trying to learn on my own and don't really have anyone to ask about problems


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,308
    Thanks
    181
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: easy prob, just not for me

    Welcome to the forums. Please see Forum Guidelines for instructions on how to preserve code formatting.

    I'm not sure I know what the question is. Does it compile? Are there exceptions? Does it misbehave (and if so, how)? Further, the classes within your code are not part of any standard java package, and are classes which many may not be familiar with.

  3. #3
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    411
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: easy prob, just not for me

    I haven't ever used ACM graphic libraries, but
    from what I am guessing your setColor method
    should have a Boolean argument passed to it -
    possibly "true" so the compiler knows the color
    should be set.

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    — Augusta Ada Byron, Lady Lovelace (1851)

  4. #4
    Junior Member
    Join Date
    Aug 2014
    Posts
    15
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: easy prob, just not for me

    ok, sorry if posted wrong, was I just supposed to put the code part like this
     import acm.graphics.*;
     import acm.program.*;
     import java.awt.*;
     
     public class Target extends GraphicsProgram { 
     public void run() {
     
     GRect Square = new GRect(100,100,50,50);
     Square.setColor(Color.BLACK);
     Square.setFillColor(Color.BLACK);
     add(Square);
     
     
     }
     }
    .
    Again sorry for being unclear, I am using eclipse and I am just trying to make a square and color it in black.

    with the code above it draws the square and will allow me to do other things to it like change the border color but not color it in black.
    Last edited by stanfordjava; August 6th, 2014 at 09:51 PM. Reason: code still not right format

  5. #5
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    411
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: easy prob, just not for me

    Your first method could be invalid.
    The compiler does not know whether to fill the square or not.

    Square.setColor(Color.BLACK);
    Change that to
    <instance>.setFilled(Boolean);

    Where instance is the object name and Boolean represents
    the truth/falsity of the shape being filled in the said colour.

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    — Augusta Ada Byron, Lady Lovelace (1851)

  6. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,308
    Thanks
    181
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: easy prob, just not for me

    Your first method could be invalid.
    The description by the OP sounds like a runtime problem rather than a compile time problem. That being said I think you're on the right track in that one must configure the GRect object appropriately (eg add rather than change that method).

    All this being said, I've never been quite sure about the purpose of this library - I see it used on forums here and there by beginners, but to me seems to abstract away some of the more important concepts of Swing programming.

  7. #7
    Junior Member
    Join Date
    Aug 2014
    Posts
    15
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: easy prob, just not for me

    public void run() {
    		GRect Square = new GRect(100,100,50,50);
    		Square.setFilled(Square.isFilled());
    		Square.setFillColor(Color.BLACK);
    		add(Square);

    I am still not sure if I am doing this right, I am trying to follow a you tube class that is pretty old so maybe that is the problem.

    I cant believe a simple square is giving me this much trouble lol,

    --- Update ---

    I am just following along with a university computer programming course and that is just what they use. I would be open to suggestions on the best videos to watch for learning to code, although it is several years old. I have seen some videos on here but I am sure you may know of ones that are very clear and not to fast pasted. Thanks
    Last edited by stanfordjava; August 7th, 2014 at 06:39 PM. Reason: highlight code

  8. #8
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,308
    Thanks
    181
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: easy prob, just not for me

    This is the reason for my statement above in post #6 - even the API for this library does not indicate what the default behavior is of 'GRect'.
    Generated Documentation (Untitled)
    Based upon you're experience, I presume it is false. So, to fill the object you must set the filled flag to true.

    All this being said, I'd recommend skipping the layer of obfuscation (eg this 'acm' library) and build things from the ground up
    Trail: 2D Graphics (The Java™ Tutorials)

  9. #9
    Junior Member
    Join Date
    Aug 2014
    Posts
    15
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: easy prob, just not for me

    Quote Originally Posted by Ada Lovelace View Post
    Your first method could be invalid.
    The compiler does not know whether to fill the square or not.



    Change that to
    <instance>.setFilled(Boolean);

    Where instance is the object name and Boolean represents
    the truth/falsity of the shape being filled in the said colour.

    Wishes Ada xx
    Thanks for this, I wasn't sure how to put Boolean in, just the word true worked like

    Square.setFilled(true);

  10. #10
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    411
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: easy prob, just not for me

    I'm not certain but I think the ACM library is created by an independent organisation
    that Oracle/Sun gave approval to for creating a more simplistic version of AWT/Swing for
    beginners in Java. You can actually download the Jar file for ACM, link it to Eclipse via
    'add libraries' and it will compile and run the associated libraries.

    That being said, I do agree with copeg in the fact that it is indeed 'non-standard Java' and
    if the OP was to continue using it, that is fine in the short-term, but bare in mind in industry
    ACM is not really used, and learning the standard Java libraries would indeed be a benefit.

    Have you managed to solve the problem now? @stanfordjava

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    — Augusta Ada Byron, Lady Lovelace (1851)

  11. #11
    Junior Member
    Join Date
    Aug 2014
    Posts
    15
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: easy prob, just not for me

    Yes thank you I have solved the problem now, I am a little discouraged now thinking I am wasting my time with what I am learning. It is a Stanford University lecture but it is from 2008. I just figured It wouldn't change much and what I learn would be easily transferable to methods today, was I wrong in thinking that? Are there videos for learning java? I find it very dry just learning by reading a book.

    --- Update ---

    I have also found the problem in my ways, I am not learning a course that teaches java but rather to teach basic programming methodology.
    The version of eclipse I am using is just an eclipse with plugins to make it easier for class use for downloading and submitting projects. So I am going to continue on with this course in hopes it makes things easier down the road, from what I have read in the comment of these videos are that while this material is older and out dated the basic ideas and ideology are the same.

  12. #12
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    411
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: easy prob, just not for me

    I can understand what your saying, and yes learning from a book can be tedious and boring
    at times, but probably does give you more information about a subject and in greater detail.
    Like said previously, there is nothing wrong with what you are learning. You are still learning
    how to program
    - and that doesn't matter if your using Java, C, C++ or Visual Basic. All
    languages have a similar structure and learning the bare bones of it - even with non-standard
    syntax, is still enforcing how a class is made, how a method is created and invoked, how an
    instance of a class is used etc.

    What myself and others have suggested is that after you finish the course, you will have to start
    learning standard Java syntax.

    I believe ACM does not read input like this:

    int number = input.nextInt();

    Where input as an instance of class Scanner and nextInt() is a standard
    Java console input method for integers.

    Having said all this, do not feel discouraged from what you are learning. Like I
    said before, you will have a better understanding of what the standard syntax is
    when you do learn it, because you can relate to what the course taught you.

    Keep working hard and good luck!

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    — Augusta Ada Byron, Lady Lovelace (1851)

Similar Threads

  1. Replies: 8
    Last Post: February 12th, 2013, 04:45 AM
  2. Easy.
    By Totel in forum Loops & Control Statements
    Replies: 3
    Last Post: September 26th, 2012, 03:19 PM
  3. This will be an easy one.
    By Pedroski in forum Object Oriented Programming
    Replies: 2
    Last Post: September 26th, 2011, 12:53 AM
  4. Prob in Loading Textures
    By sikriyogesh in forum Java Theory & Questions
    Replies: 0
    Last Post: December 15th, 2009, 04:59 AM
  5. Cummulative Sum prob.. need some help!
    By ravij in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 21st, 2009, 04:31 PM

Tags for this Thread