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 5 of 5 FirstFirst ... 345
Results 101 to 120 of 120

Thread: javadisplay images

  1. #101
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,618
    Thanks
    45
    Thanked 1,958 Times in 1,932 Posts

    Default Re: javadisplay images

    From post#92, re-ordered:

    1)image created
    2) new image added to a panel
    3) button added to panel
    4)panel with the image and the button added to the panel with the gridlayout
    5)filled panel added to the frame
    6)GUI packed and shown
    If you don't understand my answer, don't ignore it, ask a question.

  2. #102
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,618
    Thanks
    45
    Thanked 1,958 Times in 1,932 Posts

    Default Re: javadisplay images

    It looks like steps 5 and 6 (from post#106) are not done last. They are done before steps 2, 3 & 4

    For learning how to create a GUI make a test program as done in post #51. When that works, change it by using post#70.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: javadisplay images

    I wish rather than you telln m to make a test program just explain where im going wrong to help e understand, as you can see i have been tryn extremely hard to try and sort this.

    i really do appreciate your help honestly but now im just really frustrated and cus its been a good few days and im just going round in circles, i need to show my tutor and i wont have it complete

  4. #104
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,618
    Thanks
    45
    Thanked 1,958 Times in 1,932 Posts

    Default Re: javadisplay images

    The order of the steps is important.


    Try the steps in the order I recommended and see what happens then.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: javadisplay images

    ive ammended it so its it is in right order now jsut not printing out the the way i want it to, there i somthing im doing wrong but i dont knw what.
    Last edited by stresstedout; March 4th, 2014 at 12:57 AM.

  6. #106
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,618
    Thanks
    45
    Thanked 1,958 Times in 1,932 Posts

    Default Re: javadisplay images

    Now what about step 4?

    is this in the wrong place?
    That has nothing to do with creating the GUI.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: javadisplay images

    is this not step 4 ????

    JPanel cellPanel = new JPanel(new BorderLayout());
    cellPanel.add(gridPanel);

  8. #108
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,618
    Thanks
    45
    Thanked 1,958 Times in 1,932 Posts

    Default Re: javadisplay images

    4)panel with the image and the button added to the panel with the gridlayout

    No. That code does the opposite: adds gridpanel to the cellpanel (which should contain the image and button) Look at post#70
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: javadisplay images

    i have added it there because if i put these anywhere else they give me errors.

    when i put this at the top i get errors espeically that "icon" so im not sure on what to do here.
    Last edited by stresstedout; March 4th, 2014 at 12:58 AM.

  10. #110
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,618
    Thanks
    45
    Thanked 1,958 Times in 1,932 Posts

    Default Re: javadisplay images

    4)panel with the image and the button added to the panel with the gridlayout

    That says to create a panel, add the two things to it and add that panel to the gridpanel. See post#70

    That's it for me tonight. I'll be back tomorrow.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: javadisplay images

    please can u tell me where to put the code i need to show my tutor pleaseeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee before u go

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

    Default Re: javadisplay images

    For the very last time ....

    import java.awt.*;
    import java.net.*;
    import javax.swing.*;
     
    public class ButtonAndImageGrid {
        private static String[] isbnCodes = { "0636920026518", "0636920030713",
                "9781782170303", "0636920028499", "0636920028925", "9781849699617"
        };
     
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    JFrame frame = new JFrame("Button And Image Grid");
                    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
     
                    JPanel gridPanel = new JPanel(new GridLayout(0, 4, 10, 10));
     
                    for (int i = 0; i < isbnCodes.length; i++) {
                        URL imgUrl;
     
                        try {
                            imgUrl = new URL("http://akamaicovers.oreilly.com/images/" + isbnCodes[i] + "/cat.gif");
                        } catch (MalformedURLException e) {
                            System.out.println(e);
                            continue;
                        }
     
                        ImageIcon icon = new ImageIcon(imgUrl);
     
                        JButton cellButton = new JButton(isbnCodes[i]);
                        JLabel cellLabel = new JLabel(icon);
     
                        JPanel cellPanel = new JPanel(new BorderLayout());
                        cellPanel.add(cellButton, BorderLayout.NORTH);
                        cellPanel.add(cellLabel, BorderLayout.CENTER);
     
                        gridPanel.add(cellPanel);
                    }
     
                    frame.getContentPane().add(gridPanel, BorderLayout.CENTER);
                    frame.pack();
                    frame.setVisible(true);
                }
            });
        }
    }
    Andrea, www.andbin.net SCJP 5 (91%) SCWCD 5 (94%)

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

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

    Default Re: javadisplay images

    [QUOTE=andbin;138842]For the very last time ....


    after all this and the stress i dont think i need it need. im making a learing application.. how will my users learn from this memory is what my tutor asked me?
    Last edited by stresstedout; March 4th, 2014 at 12:58 AM.

  14. #114
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,618
    Thanks
    45
    Thanked 1,958 Times in 1,932 Posts

    Default Re: javadisplay images

    I'm not sure I understand what you are asking. Is it a question about the code or what?
    If you don't understand my answer, don't ignore it, ask a question.

  15. #115
    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
    after all this and the stress i dont think i need it need. im making a learing application.. how will my users learn from this memory is what my tutor asked me?
    Honestly I also did not understand this english phrase .....
    Andrea, www.andbin.net SCJP 5 (91%) SCWCD 5 (94%)

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

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

    Default Re: javadisplay images

    I am making a project for children in school, the project is a LEARNING PROJECT.
    I thought id make a memory game but when i showed my tutor he asked me what are they learning from this. so i have wasted my time trying to make this game.

    I spent quite a long time trying to make this memory game so i dont want it to go to waste,
    i like the fact i have used images from database which will get me extra marks but what do i do with those images now.

    Can anyone suggest anything i could to do?? we have images on a jframe. how can i use images (images can either be to do with numeracy or words) to make a simple learning application or game?
    Please help me with some easy ideas, as i do not have much time.

  17. #117
    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
    Can anyone suggest anything i could to do?? we have images on a jframe. how can i use images (images can either be to do with numeracy or words) to make a simple learning application or game?
    Please help me with some easy ideas, as i do not have much time.
    stresstedout, listen please. This thread has arrived at post #123 (with my current answer) and we have spoken about a lot of things. Still now I don't know if you have well understood the concepts and examples I have posted. And you not even have answered positively or negatively about this ..... I suppose of no .....
    And now you say, if I understand correctly, that you don't know what you want to/can do??

    I wasted my time in trying to repeat things many times and posting different examples and I was a bit frustrated by this. Sorry but this is not a good incentive (at least for me) to continue on this thread/topic and I also think this is not the right way to use the forum .....
    Andrea, www.andbin.net SCJP 5 (91%) SCWCD 5 (94%)

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

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

    Default Re: javadisplay images

    Andbin, I thought of making a memory and thats what i have been doing with help of youself and norm, i am really appreciate that you took time out to help me. I have un
    Last edited by stresstedout; March 4th, 2014 at 12:58 AM.

  19. #119
    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
    Can anyone suggest anything i could to do?? we have images on a jframe. how can i use images (images can either be to do with numeracy or words) to make a simple learning application or game?
    So you want an idea for a game? There are lot of games that are made with a "grid" of images: Tic-tac-toe, Chess, Reversi, Peg solitaire, Sudoku, Scrabble. Just to name a few.

    In these games the difficulty, at programming level, is not the display of images! The real difficulty is about all the "logic" that is behind the game. This logic can be very complex, you need not just some tens of lines of code but hundreds of lines.
    And if for a game you want to develop some sort of "artificial intelligence" for a computer player, the complexity raises by 40, 50 times so that you need thousands and thousands of lines of code.
    And If you don't write this code using all the good OOP principles, design patterns, valid data structures, etc.. you will end up to a code that is only absurd, incomprehensible, clunky and so on ...

    Quote Originally Posted by stresstedout View Post
    my intentions where not to upset you, i am extremely sorry if i have done, you have not wasted your time cus i have learnt from what you have posted. Hope you can forgive me
    I can understand .... and remember (for the future), that I like to help but I like people who have good will and want to read, study, try and experiment in order to understand.
    Andrea, www.andbin.net SCJP 5 (91%) SCWCD 5 (94%)

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

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

    Default Re: javadisplay images

    Thank you andbin

Page 5 of 5 FirstFirst ... 345

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