Page 2 of 2 FirstFirst 12
Results 21 to 28 of 28
Like Tree1Likes

Thread: Not exactly the code works correctly ( JFrame, awt)

  1. #21
    Tony is offline Member
    Join Date
    Nov 2013
    Posts
    12
    Rep Power
    0

    Default Re: Not exactly the code works correctly ( JFrame, awt)

    Pictures like lining up in a row.

    As you can see I added only the array x. If I add more y and inside, the window is white, did not work, please can someone help fix it

  2. #22
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,853
    Rep Power
    19

    Default Re: Not exactly the code works correctly ( JFrame, awt)

    Well, you are drawing 5000 100x100 squares onto a 500x500 window.
    So that isn't surprising that, when you use both arrays (rather than just supplying 'a', and using a constant 'y'), that the whole screen is white.
    There's not enough acreage to hold that number of things of that size.

    So, now you need to think about how you want this to work.
    Going by your original post, you want a "map" that covers 4500x4500 px. I would shrink your stars to as small as you think would look reasonable. Even the 50x50 oval you had originally is quite a large blob on the screen.
    Next treat your JPanel as a "window" onto this map. So you'll need something that tells you what the coordinate of the (eg) top left corner of the JPanel is, relative to the underlying big map.
    Then, you can use that as an offset for all your stars, painting only the ones that would actually be visible.

    If this sounds like a lot then you're not wrong, at least from a newbie point of view.
    But, at the end of it, you'll understand how all this painting stuff works.

    Of course, this is done on the basis of a fairly limited idea of what you are actually trying to achieve and it is quite possible I've missed something in your requirements.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #23
    Tony is offline Member
    Join Date
    Nov 2013
    Posts
    12
    Rep Power
    0

    Default Re: Not exactly the code works correctly ( JFrame, awt)

    I do not know, I give up ...)
    I don `t know is that you can ask napisat.Nado somewhere else. Who then is the solution (code) that works?

  4. #24
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,415
    Rep Power
    5

    Default Re: Not exactly the code works correctly ( JFrame, awt)

    Don't give up because you are so close. Here is a suggestion. Change 5000 to 5. And change y in your paintComponent to b[i]. However, notice that the colors are not changing. That is because, unlike the coordinates you did not save the color. So you need to create a Star class to simply hold the appropriate state you want to display. Then generate the appropriate number of stars and store them. In the paintComponent as you interate over the list of stars the coordinates and color will be there for you.

    Note: Earlier, I said you didn't need a Star class. That was assuming you were creating the necessary state inside your paintComponent. So every time the window needed to be repainted, the "Stars" would change. Now you need to save that info so the stars remain fixed even when you adjust the window.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  5. #25
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default Re: Not exactly the code works correctly ( JFrame, awt)

    Quote Originally Posted by Tony View Post
    I do not know, I give up ...)
    I don `t know is that you can ask napisat.Nado somewhere else. Who then is the solution (code) that works?
    That's the spirit: giving up and begging for code ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #26
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default Re: Not exactly the code works correctly ( JFrame, awt)

    ... and also read my original relply #4; it addresses the same issue as mentioned by Jim ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #27
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,853
    Rep Power
    19

    Default Re: Not exactly the code works correctly ( JFrame, awt)

    Quote Originally Posted by jim829 View Post
    Don't give up because you are so close. Here is a suggestion. Change 5000 to 5. etc etc
    I would also shrink the size of the "stars" to 10x10, rather than 100x100.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #28
    Tony is offline Member
    Join Date
    Nov 2013
    Posts
    12
    Rep Power
    0

    Default Re: Not exactly the code works correctly ( JFrame, awt)

    THANK YOU!!!!!!
    I worked out! You are the best!

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Code works but nothing shows
    By Hagelslag in forum New To Java
    Replies: 2
    Last Post: 01-21-2013, 06:03 PM
  2. Did I comment this code correctly?
    By Vinx in forum New To Java
    Replies: 5
    Last Post: 06-17-2012, 01:50 AM
  3. Sorting code not working correctly
    By jubbiejub in forum New To Java
    Replies: 3
    Last Post: 05-01-2012, 01:28 AM
  4. Replies: 3
    Last Post: 10-29-2011, 12:39 AM
  5. Please explain how this bit of code works.
    By Allspark in forum New To Java
    Replies: 4
    Last Post: 09-03-2010, 03:56 AM

Tags for this Thread

Posting Permissions

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