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.

Page 2 of 5 FirstFirst 1234 ... LastLast
Results 26 to 50 of 120

Thread: javadisplay images

  1. #26
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,952
    Thanks
    56
    Thanked 2,353 Times in 2,324 Posts

    Default Re: javadisplay images

    My only suggestion now is that you drop this course. Programming requires attention to lots of small details.
    If you don't want to do that, then you'll have a hard time with programming.
    If you don't understand my answer, don't ignore it, ask a question.

  2. #27
    Member
    Join Date
    Jan 2014
    Posts
    209
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: javadisplay images

    why dont you just help me out in tryning to figure this out?

    i have 1 image displayed in my frame how do i do 2 image?

  3. #28
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,952
    Thanks
    56
    Thanked 2,353 Times in 2,324 Posts

    Default Re: javadisplay images

    I thought that was what I was trying to do. I'm not going to write the code, I expect you to do that.

    Did you do what I suggested here:
    How many times does the code go around the while() loop? Add a println() statement inside the loop so you can see how many times the loop is executed.
    That will tell you how many images are being returned.

    Also can you answer these questions:
    Can you describe in English what the program should do with the bytes it reads into the image array in posts #7 and #19?
    Every time around the loop a new set of bytes is read into the image array.
    What needs to be done each time some bytes are read into the array?
    If you don't understand my answer, don't ignore it, ask a question.

  4. #29
    Member
    Join Date
    Jan 2014
    Posts
    209
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: javadisplay images

    20
    each time the bytes are read it displays another image

  5. #30
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,952
    Thanks
    56
    Thanked 2,353 Times in 2,324 Posts

    Default Re: javadisplay images

    each time the bytes are read it displays another image
    Ok. What are the steps the code needs to do for that to happen?
    If you don't understand my answer, don't ignore it, ask a question.

  6. #31
    Member
    Join Date
    Jan 2014
    Posts
    209
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: javadisplay images

    IS THIS CORRECT?
    Last edited by stresstedout; March 4th, 2014 at 01:51 AM.

  7. #32
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: javadisplay images

    Quote Originally Posted by stresstedout View Post
    IS THIS CORRECT?
    Not exactly .... and don't use available() if you don't know exactly what it does!

    Yesterday I told you some things and more than one time. I don't understand why you don't understand .....


    while (result.next()) {
        byte[] image = .........;    // get the array of bytes for the image on current record
        // create the java.awt.Image using Toolkit
        // scale or do other things on the image
        // create an ImageIcon
        // create a JLabel
        // add the JLabel into a container
    }

    What's the difficulty about this? You have done all these single things but not in this way.
    Andrea, www.andbin.net SCJP 5 (91%) SCWCD 5 (94%)

    Useful links for Java beginners My new project Java Examples on Google Code

  8. #33
    Member
    Join Date
    Jan 2014
    Posts
    209
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: javadisplay images

    Quote Originally Posted by andbin View Post
    Not exactly .... and don't use available() if you don't know exactly what it does!

    Yesterday I told you some things and more than one time. I don't understand why you don't understand .....


    while (result.next()) {
        byte[] image = .........;    // get the array of bytes for the image on current record
        // create the java.awt.Image using Toolkit
        // scale or do other things on the image
        // create an ImageIcon
        // create a JLabel
        // add the JLabel into a container
    }

    What's the difficulty about this? You have done all these single things but not in this way.
    In the database i have these at the moment. im not sure on how to complete this bit of the code.

    byte[] image = .........; // get the array of bytes for the image on current record

    [BLOB - 2.7 KiB]
    [BLOB - 6.3 KiB]
    [BLOB - 13.9 KiB]

  9. #34
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,952
    Thanks
    56
    Thanked 2,353 Times in 2,324 Posts

    Default Re: javadisplay images

    Did the code in post#1 create an image and show it in the GUI?
    Can you change the code so that it creates an image each time the image array is filled with bytes instead of only creating one image AFTER the loop finishes?
    If you don't understand my answer, don't ignore it, ask a question.

  10. #35
    Member
    Join Date
    Jan 2014
    Posts
    209
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: javadisplay images

    yes the code in post#1 shows the last image on the gui.
    im not sure on how to change the code to allow it to create an image each time the image array is filled with bytes, that is where i am stuck.
    im not sure on how to code it, i have done research and tried different codes, but im not getting anywhere jst end up with my original code

  11. #36
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,952
    Thanks
    56
    Thanked 2,353 Times in 2,324 Posts

    Default Re: javadisplay images

    to create an image each time the image array is filled with bytes
    One way would be to move the } at the end of the loop so that the code that creates the image is inside the loop and is executed immediately after the bytes are read.
    If you don't understand my answer, don't ignore it, ask a question.

  12. #37
    Member
    Join Date
    Jan 2014
    Posts
    209
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: javadisplay images

    Quote Originally Posted by Norm View Post
    One way would be to move the } at the end of the loop so that the code that creates the image is inside the loop and is executed immediately after the bytes are read.
    its not showing a gui frame now

  13. #38
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,952
    Thanks
    56
    Thanked 2,353 Times in 2,324 Posts

    Default Re: javadisplay images

    Can you post the code that you changed that shows where the } was moved to?
    If you don't understand my answer, don't ignore it, ask a question.

  14. #39
    Member
    Join Date
    Jan 2014
    Posts
    209
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: javadisplay images

    ive done it.. i have all three images on my gui frame now. ta for all your patience guys and for keeping me going and sorry for my frustration.
    Last edited by stresstedout; February 6th, 2014 at 07:26 AM. Reason: error

  15. #40
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,952
    Thanks
    56
    Thanked 2,353 Times in 2,324 Posts

    Default Re: javadisplay images

    i have all three images
    What happened to the other 17 images? I thought there were 20 images.
    If you don't understand my answer, don't ignore it, ask a question.

  16. #41
    Member
    Join Date
    Jan 2014
    Posts
    209
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: javadisplay images

    there are going to be 20 images yes, i need to find what i want to put in the game and get them in the database and then up on the gui. i was only testing with 3.
    to sort out the images in there on label to spread them out do i need to use gridlayout?

    --- Update ---

    Now that i have the images on the gui, i need to:
    1) sort out the layout which isnt going to be easy.
    2) add buttons on top of each label
    3) programming the game so when a button is pressed it reveals the image and stays up right, another button is pressed and it reveals that images, if they are the same they stay upright if not then they go back to orignal state.

    do you have any thing that could help me ??

  17. #42
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: javadisplay images

    Quote Originally Posted by stresstedout View Post
    1) sort out the layout which isnt going to be easy.
    This depends on what you want .....
    Layouting with AWT/Swing is not difficult ..... if you have the "basics".

    Quote Originally Posted by stresstedout View Post
    2) add buttons on top of each label
    Each "cell" in GridLayout can contain only 1 component. Instead to put a JLabel into a cell, you should put a JPanel that contains JLabel and JButton laid out using another layout manager (e.g. BorderLayout).

    Quote Originally Posted by stresstedout View Post
    3) programming the game so when a button is pressed it reveals the image and stays up right, another button is pressed and it reveals that images, if they are the same they stay upright if not then they go back to orignal state.
    Wait .... I guess you are doing a "memory" game .....
    Are you sure that label+button is a good presentation? Why can't you (or don't want) use mouse events directly on JLabel?
    Andrea, www.andbin.net SCJP 5 (91%) SCWCD 5 (94%)

    Useful links for Java beginners My new project Java Examples on Google Code

  18. #43
    Member
    Join Date
    Jan 2014
    Posts
    209
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: javadisplay images

    Quote Originally Posted by andbin View Post
    Wait .... I guess you are doing a "memory" game .....
    Are you sure that label+button is a good presentation? Why can't you (or don't want) use mouse events directly on JLabel?
    yh it is a memory game, im not sure or what would be better? should i use mouse events directly JLabel? would that mean i would have no buttons?

  19. #44
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: javadisplay images

    Quote Originally Posted by stresstedout View Post
    yh it is a memory game, im not sure or what would be better?
    There are many ways to develop and present a "memory" game (just only considering Swing as GUI), so there isn't a unique answer/possibility.

    Quote Originally Posted by stresstedout View Post
    should i use mouse events directly JLabel?
    Technically it's perfectly possible.

    Quote Originally Posted by stresstedout View Post
    would that mean i would have no buttons?
    Using mouse events on JLabel, yes, there's no need of buttons for the cards.
    Andrea, www.andbin.net SCJP 5 (91%) SCWCD 5 (94%)

    Useful links for Java beginners My new project Java Examples on Google Code

  20. #45
    Member
    Join Date
    Jan 2014
    Posts
    209
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: javadisplay images

    okay i will try and get back to you if i get stuck. ta

  21. #46
    Member
    Join Date
    Jan 2014
    Posts
    209
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: javadisplay images

    i am struggling abit i like the look of what i have on my frame, but i just need to get the gaps small for each icon.. can anyone suggest anything as i have no clue

  22. #47
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: javadisplay images

    Quote Originally Posted by stresstedout View Post
    but i just need to get the gaps small for each icon..
    What do you mean? Can you be more precise?
    Andrea, www.andbin.net SCJP 5 (91%) SCWCD 5 (94%)

    Useful links for Java beginners My new project Java Examples on Google Code

  23. #48
    Member
    Join Date
    Jan 2014
    Posts
    209
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: javadisplay images

    Quote Originally Posted by andbin View Post
    What do you mean? Can you be more precise?
    i want to position them in a grid with not to much space between. so each label is not too far apart from each other.
    because they all print out on to the screen there is no way for me to modify it by sayin label1 label2 so im a little confused
    Last edited by stresstedout; February 7th, 2014 at 07:30 AM. Reason: extra

  24. #49
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: javadisplay images

    Quote Originally Posted by stresstedout View Post
    i want to position them in a grid with not to much space between. so each label is not too far apart from each other.
    because they all print out on to the screen there is no way for me to modify it by sayin label1 label2 so im a little confused
    GridLayout does a simple thing: it takes the size of the container (in which GridLayout is assigned) and divides it in NxM equally sized cells. So the main question is: who controls the size of the container? This depends ....

    If you put a JPanel with GridLayout into the CENTER area of BorderLayout in the content pane, then the size of GridLayout is directly dependent on the size of the frame .... not on the sizes of components into the cells.
    If you do this and you enlarge very much the frame, each cell is very big. Each JLabel physically fills the space of the cell, however the image in JLabel does not stretch (this is not a functionality of JLabel) so you see a large space between images.

    Keeping the same structure, if you do an initial pack() on the frame, then the GridLayout is sized to its "preferred" size. It means: each cell has the size of the largest JLabel. Since I guess you have same size for all images, you have the minimum size, plus eventual gaps (configurable in GridLayout).

    If you put a GridLayout into a component that "respect" the preferred size, you have always this same effect.
    Andrea, www.andbin.net SCJP 5 (91%) SCWCD 5 (94%)

    Useful links for Java beginners My new project Java Examples on Google Code

  25. #50
    Member
    Join Date
    Jan 2014
    Posts
    209
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: javadisplay images

    are you able to show me a little example? also what is inital pack??? and where does this code go??


    Quote Originally Posted by andbin View Post
    GridLayout does a simple thing: it takes the size of the container (in which GridLayout is assigned) and divides it in NxM equally sized cells. So the main question is: who controls the size of the container? This depends ....

    If you put a JPanel with GridLayout into the CENTER area of BorderLayout in the content pane, then the size of GridLayout is directly dependent on the size of the frame .... not on the sizes of components into the cells.
    If you do this and you enlarge very much the frame, each cell is very big. Each JLabel physically fills the space of the cell, however the image in JLabel does not stretch (this is not a functionality of JLabel) so you see a large space between images.

    Keeping the same structure, if you do an initial pack() on the frame, then the GridLayout is sized to its "preferred" size. It means: each cell has the size of the largest JLabel. Since I guess you have same size for all images, you have the minimum size, plus eventual gaps (configurable in GridLayout).

    If you put a GridLayout into a component that "respect" the preferred size, you have always this same effect.
    Last edited by stresstedout; February 7th, 2014 at 08:08 AM. Reason: oops

Page 2 of 5 FirstFirst 1234 ... LastLast

Similar Threads

  1. No images being displayed
    By Leonardo1143 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 5th, 2013, 03:57 PM
  2. Images
    By Hoshi in forum Java Theory & Questions
    Replies: 1
    Last Post: September 6th, 2012, 11:54 PM
  3. Images in GridLayout
    By BuhRock in forum AWT / Java Swing
    Replies: 4
    Last Post: November 5th, 2011, 01:15 AM
  4. What are the best way of placing images in GUI?
    By Ciwan in forum AWT / Java Swing
    Replies: 5
    Last Post: February 26th, 2009, 05:19 PM

Tags for this Thread