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 1 of 5 123 ... LastLast
Results 1 to 25 of 120

Thread: javadisplay images

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

    Unhappy javadisplay images

    I am trying to get
    Last edited by stresstedout; March 4th, 2014 at 01:50 AM.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: javadisplay images

    For better help sooner, post an SSCCE demonstrating exactly what you're doing. If you're having trouble displaying more than one image, your example should be code that tries to show two images.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

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

    Default Re: javadisplay images

    rather than telling me what to post and what not to why dont u just help!! man all u people on these forums just know how to upset and make someone feel horrible.

    i have been trying to do this for days now, i have tired a while loop, i have also tried to override each previous value, and use the last to set the image but im just confused!! so if u have somthing that can help me then please or just dont comment

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: javadisplay images

    Quote Originally Posted by stresstedout View Post
    rather than telling me what to post and what not to why dont u just help!! man all u people on these forums just know how to upset and make someone feel horrible.

    i have been trying to do this for days now, i have tired a while loop, i have also tried to override each previous value, and use the last to set the image but im just confused!! so if u have somthing that can help me then please or just dont comment
    The code you posted is impossible to debug. It's too small of a window into what you're actually doing, and it includes stuff that has nothing to do with your problem. That's why I asked for an SSCCE. Isolating the problem is a fundamental skill to have when programming, and half the time you'll find the problem yourself during the process of creating the SSCCE. If you provide that, I'd be happy to help. This is a technical forum, so we don't have a lot of room for tantrums and whining. It's up to you how to proceed from here.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

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

    Default Re: javadisplay images

    i am makin a
    Last edited by stresstedout; March 4th, 2014 at 01:50 AM.

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: javadisplay images

    When posting code, please use the highlight tags to preserve formatting. Also, I recommend using standard naming conventions- classes start with upper-case letters, methods and variables start with lower-case letters.

    And like I said, the name of the game is "isolating the problem". Which part of this is breaking? Reading from the database, or displaying the images? Can you read images from hardcoded file paths? Can you display those hardcoded images, without trying to load from a database? Separately, can you load from a database without displaying the images? You have to isolate the problem down to its smallest piece. That's why it's recommended that you code one small piece of your program at a time instead of trying to code the whole thing at once and then hoping for the best.

    So I would say your next step is to isolate the problem: which part is giving you trouble, loading from the database or displaying images?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

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

    Default Re: javadisplay images

    Displaying the images is my problem
    Last edited by stresstedout; March 4th, 2014 at 01:50 AM. Reason: update

  8. #8
    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
    while (result.next()) {
    image = result.getBytes("content");
    }
    Image img = Toolkit.getDefaultToolkit().createImage(image);
    Here you are not creating 1 image for each record .... you have "exausted" the record set and then after, at the end, you create 1 image.
    So what can you expect from a similar code?
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

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

    Default Re: javadisplay images

    how am i able to display imagess from the database in labels to jframe?

    i think im cofused, i been tryiing to fix it but getting no were.

  10. #10
    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
    how am i able to display imagess from the database in labels to jframe?
    If you have 1 image in each record, then create the image for each record. That is, into the loop. Not outside.
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

  11. #11
    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 give me an example?

  12. #12
    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
    are you able to give me an example?
    while (result.next()) {
    image = result.getBytes("content");
    }
    // Here you have exausted the record-set. And you have not created any image (just got the raw image stream).
     
    // Here you create 1 Image only, with the last image stream.
    Image img = Toolkit.getDefaultToolkit().createImage(image);
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

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

    Default Re: javadisplay images

    so i need to add a url?

  14. #14
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: javadisplay images

    Quote Originally Posted by stresstedout View Post
    so i need to add a url?
    No. You need to understand how scope and assignment works. For example:

    int x = 0;
    for(int i = 0; i < 10; i++){
       x = i;
    }
    System.out.println(x);

    According to your code, x should print 0-9, which obviously isn't true.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

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

    Default Re: javadisplay images

    now im seriously confused!

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: javadisplay images

    Each time the bytes for an image are stored in the image array, the code must make an image from those bytes. Otherwise only the bytes for the last image are in the image array when an image is made from those bytes. All the previously read bytes are gone.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: javadisplay images

    i have been trying to do this for 2 weeks now, not getting no were. i cnt do it. ta anyways

  18. #18
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: javadisplay images

    That's the spirit!

    Instead of giving up, trace through your program logically. Let's say your results are ImageOne, ImageTwo, and ImageThree.

    You get the first result, then set image equal to ImageOne. You then loop and set image equal to ImageTwo. Then you loop again and set image equal to ImageThree. Notice that you haven't done anything with ImageOne or ImageTwo!

    You then exit the loop and do something with image, which is still set to ImageThree. Your question is about why ImageOne and ImageTwo are being ignored, and the answer is because you are ignoring them.

    That's why I asked you to break down your problem: your first problem has nothing to do with displaying images, and has only to do with fetching results from a database. Even simpler than that, your problem is with scope and assignment, which we've explained a couple of different ways now.

    I can't stop you from giving up, but the act of narrowing down your problem and focusing on one small piece at a time *is* programming. I recommend starting with a smaller program, maybe one that just gets a List of results from a database and prints them out?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

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

    Default Re: javadisplay images

    \rrrgh
    Last edited by stresstedout; March 4th, 2014 at 01:51 AM. Reason: UPDATE

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: javadisplay images

    What does the code do with the contents of the image array after it is given a value inside the loop?
    The contents of the image array is what is needed to create an Image object with the createImage() method.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: javadisplay images

    sir i really am stuck, ive been trying to figure this out all day now and its 1am, please help me im confused
    Last edited by stresstedout; March 4th, 2014 at 01:51 AM. Reason: update

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: javadisplay images

    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?

    I have no idea what the posted code in #21 has to do with your current problem.
    If you don't understand my answer, don't ignore it, ask a question.

  23. #23
    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
    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?

    I have no idea what the posted code in #21 has to do with your current problem.
    i am makin a match game,in order to do that i have been trying to add image to my sql database which i have completed, those images which are in the database i would like them to be on a jframe in jlabels and have buttons on top so so i click the button the image shows under, and u press another button and the image shows if they match they stay up right if not go back to nomal.

    The problem i have i was able to get the code working for displaying 1 image but i cnt do more than 1.. i need 20 images to be displayed from the database

  24. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: javadisplay images

    Right now work on making images from the bytes returned by the getBytes() method. Save working on the other details for later. Work on One problem at a time.

    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?

    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.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: javadisplay images

    forget it man!!

Page 1 of 5 123 ... 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, 02:57 PM
  2. Images
    By Hoshi in forum Java Theory & Questions
    Replies: 1
    Last Post: September 6th, 2012, 10:54 PM
  3. Images in GridLayout
    By BuhRock in forum AWT / Java Swing
    Replies: 4
    Last Post: November 5th, 2011, 12: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