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 4 of 5 FirstFirst ... 2345 LastLast
Results 76 to 100 of 120

Thread: javadisplay images

  1. #76
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,360
    Thanks
    49
    Thanked 2,207 Times in 2,180 Posts

    Default Re: javadisplay images

    Can you fix the formatting of the code? The indentations are not right. There are missing }s

    The posted code is a mess. There are a lot of definitions missing.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: javadisplay images

    WITHOUT THE LINE OF CODE frame.pack(); it gives me what i want but the frame has no size at all, so i have to make the screen bigger completely to see anything on the frame.

    without the code frame.pack(); it presents the data as shown on the image.

    how do i give this frame a size without using frame.pack(); code although this line of code is using for size or frame. Attachment 2690

  3. #78
    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 fix the formatting of the code? The indentations are not right. There are missing }s

    The posted code is a mess. There are a lot of definitions missing.
    here is the code
    he code so doesnt that mean that the indentation are correct?
    Last edited by stresstedout; March 4th, 2014 at 12:56 AM.

  4. #79
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,360
    Thanks
    49
    Thanked 2,207 Times in 2,180 Posts

    Default Re: javadisplay images

    Can you edit the code and format it properly?
    Nested statements should be indented
    }s should NOT be hidden at the end of statements. Put them on their own line.

    There is no errors in the code so doesnt that mean that the indentation are correct?
    No, the compiler will accept the whole program on one line.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: javadisplay images

    is this better
    Last edited by stresstedout; March 4th, 2014 at 12:56 AM.

  6. #81
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,360
    Thanks
    49
    Thanked 2,207 Times in 2,180 Posts

    Default Re: javadisplay images

    No.Too many nested statements start in the first column making it hard to read and understand the logic in the code.
    The }s should not be one above the other (in the same column)

    See post#51 for an example of proper formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #82
    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
    No.Too many nested statements start in the first column making it hard to read and understand the logic in the code.
    The }s should not be one above the other (in the same column)

    See post#51 for an example of proper formatting.
    [CODE]
    now and you can help me with my problem i got please
    Last edited by stresstedout; March 4th, 2014 at 12:56 AM.

  8. #83
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,360
    Thanks
    49
    Thanked 2,207 Times in 2,180 Posts

    Default Re: javadisplay images

    Its a little better, but there are still too many statements starting in the first column.
    And there are too many statements that are indented that should NOT be indented:
    ImageIcon icon = new ImageIcon(img);
     
                    JPanel gridPanel = new JPanel(new GridLayout(6, 0, 6, 6));
    Those two statements should start in the same column.

    Here is a hidden } that makes the code hard to read and understand
                    frame.setVisible(true);}
    At the end there is }}. }s should be on their own line and NOT in the same column
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: javadisplay images

    i have edited it and hope i have understood and corrected what you asked for
    Last edited by stresstedout; March 4th, 2014 at 12:57 AM.

  10. #85
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,360
    Thanks
    49
    Thanked 2,207 Times in 2,180 Posts

    Default Re: javadisplay images

    One problem I see inside the while loop is there are method calls being made that should only be made one time, not every time an image is created:
    setVisible() - only needs to be done ONE time after the GUI has been built
    adding to frame at BorderLayout.NORTH - only ONE component will be there, all the other add()s are useless
    pack() - only once after everything has been added
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: javadisplay images

    PLEASEEE can you tell me more about the methods?

  12. #87
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,360
    Thanks
    49
    Thanked 2,207 Times in 2,180 Posts

    Default Re: javadisplay images

    The methods should be called when they are needed to do something.
    1)When does the GUI need to be packed and shown?
    2)When does a filled panel need to be added to the frame?

    3)When should the image be created from the bytes just read from the database?
    4)When should the new image be added to a panel with a button?
    5)When should the panel with the image and the button be added to the panel with the gridlayout?
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: javadisplay images

    where do i put them gui being packed and the panel added to the frame? im confused

  14. #89
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,360
    Thanks
    49
    Thanked 2,207 Times in 2,180 Posts

    Default Re: javadisplay images

    Take the questions one at a time and decide when they should be executed. Make a list of pseudo code statements to show when each should be executed.

    This project may be too advanced for your current knowledge. Maybe you should start with something simpler.
    Look at the tutorial about how to build a GUI: Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: javadisplay images

    IS THIS WHAT YOU MEAN?
    Last edited by stresstedout; March 4th, 2014 at 12:57 AM.

  16. #91
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,360
    Thanks
    49
    Thanked 2,207 Times in 2,180 Posts

    Default Re: javadisplay images

    No, that does not look like a list of steps in pseudo code.
    The code is missing several steps.

    What does the for loop that loops 2 times do? Why is it there?

    Are there supposed to be buttons with the images?
    I don't see them in the posted code. I thought that showing them with the images was a BIG problem.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: javadisplay images

    there are buttons which go on the images to hide them... so when the use clicks the button they see the image under it..

    i need to add the buttons now, the only problem i have with them is that i cannot get them to go on the images, this is where i am struggling.
    any tips?

    do i add them in the while loop?

    also the for loop was a mistake it onli loops once

  18. #93
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,360
    Thanks
    49
    Thanked 2,207 Times in 2,180 Posts

    Default Re: javadisplay images

    What is a loop that loops once?
    problem i have with them is that i cannot get them to go on the images
    See post#70.
    Put them in a panel and add that panel to the panel with the gridlayout. See steps 4 & 5 in post#92
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: javadisplay images

    i have spent a whole 2 days tryna figure this out but all i get is errors, and now i have gone back to the orignal code.

    please can you help.. anything at all?

    i have to show my tutor tomorrow and i feel really upset that i cant do this.

  20. #95
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,360
    Thanks
    49
    Thanked 2,207 Times in 2,180 Posts

    Default Re: javadisplay images

    A suggestion to learn how to make a GUI with image over button:
    Take the code from andbin's post#51 and modify it to build panels with images over buttons using the technique shown in post#70.
    The results could look like this:
    ImageOverButton.png
    When that works, you should be able to apply the techniques to the program you are trying to build.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: javadisplay images

    I have looked through the program written by adbin and i have come up with this, but i still cannot understand of where to put the button becuse at the moment it just comes beside it. so i have left it out the code. please help
    Last edited by stresstedout; March 4th, 2014 at 12:57 AM.

  22. #97
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,360
    Thanks
    49
    Thanked 2,207 Times in 2,180 Posts

    Default Re: javadisplay images

    it just comes beside it
    look at post#70 for how to put the image above the button. There isn't any Database used in the code from post#51. Using a DB just makes it harder for this testing. Use a single image that is read from a file.

    What is the reason for this code:
         for (int i = 0; i < 1; i++)
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: javadisplay images

    that line of code is for how many times it prints the images in the columns or rows.

  24. #99
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,360
    Thanks
    49
    Thanked 2,207 Times in 2,180 Posts

    Default Re: javadisplay images

    You do NOT need a for statement that only loops one time.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: javadisplay images

    i have seen post 70 but im not sure on where to put it, where ever i put it goes beside it. please could give me a hint.. im really stuck or i wouldnt ask.

Page 4 of 5 FirstFirst ... 2345 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, 04:19 PM

Tags for this Thread