putting images on a gridlayout

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ramola
    New Member
    • Sep 2007
    • 35

    putting images on a gridlayout

    Hi, i need to know how can i put an image in a grid ?

    as in i am developing a multiplayer game so.......

    i need to display set of information like player name, score and the image of his marble.

    the best way to do this according to me is using a grid ......
    but somehow i cant place images on the grid ...

    could u suggest something ?

    kind regards,
    Malavika
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by malavikarane
    Hi, i need to know how can i put an image in a grid ?

    as in i am developing a multiplayer game so.......

    i need to display set of information like player name, score and the image of his marble.

    the best way to do this according to me is using a grid ......
    but somehow i cant place images on the grid ...

    could u suggest something ?

    kind regards,
    Malavika
    Someone has already done this kind of program here before (sorry I can't remember who) so you can try to search this forum for this.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by r035198x
      Someone has already done this kind of program here before (sorry I can't remember who) so you can try to search this forum for this.
      That was Malavikarane, (I searched on "marble" ;-)

      kind regards,

      Jos

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by JosAH
        That was Malavikarane, (I searched on "marble" ;-)

        kind regards,

        Jos
        No prizes for guessing who's had his emprezzo(?) today.

        Comment

        • Ramola
          New Member
          • Sep 2007
          • 35

          #5
          Originally posted by r035198x
          No prizes for guessing who's had his emprezzo(?) today.
          guys ..........
          plz u need to help me yarrrrr [ a hindi word synonumous to friend ]!

          I cant get it rite !!!!!!
          just abt. a hint n i know i'll b able to do it !!!

          kind reagards,
          Malavika

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by malavikarane
            guys ..........
            plz u need to help me yarrrrr [ a hindi word synonumous to friend ]!

            I cant get it rite !!!!!!
            just abt. a hint n i know i'll b able to do it !!!

            kind reagards,
            Malavika
            You did read the link that Jos posted above right?

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by r035198x
              You did read the link that Jos posted above right?
              Golly, I only noticed it just now: the OP of this thread and the OP of the 'marble'
              thread are one and the same person. What happened to the solution I gave him
              back then? Or are we beamed back in time?

              kind regards,

              Jos (<--- "Scotty; get me out of here, now!" ;-)

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Originally posted by JosAH
                Golly, I only noticed it just now: the OP of this thread and the OP of the 'marble'
                thread are one and the same person. What happened to the solution I gave him
                back then? Or are we beamed back in time?

                kind regards,

                Jos (<--- "Scotty; get me out of here, now!" ;-)
                WHAT!
                We two are ripe for defenestration.

                Comment

                • JosAH
                  Recognized Expert MVP
                  • Mar 2007
                  • 11453

                  #9
                  Originally posted by r035198x
                  WHAT!
                  We two are ripe for defenestration.
                  Yes indeed; you're right; after you Sir.

                  kind regards,

                  Jos ( <--- raised to be polite ;-)

                  Comment

                  • Ramola
                    New Member
                    • Sep 2007
                    • 35

                    #10
                    Originally posted by JosAH
                    Golly, I only noticed it just now: the OP of this thread and the OP of the 'marble'
                    thread are one and the same person. What happened to the solution I gave him
                    back then? Or are we beamed back in time?

                    kind regards,

                    Jos (<--- "Scotty; get me out of here, now!" ;-)

                    Last time it was regarding something else...
                    n this time when i wanted to put images on the grid representing players and their scores..
                    It was totally different !

                    anyways i figured out how to do it..
                    so its fine .... in a way good i didnt get help ! :)

                    but now i am facing another difficulty :

                    Its a game on LAN so the no. of players will vary each time a new game is started.

                    Accordingly the no. of entries on the score card will change .
                    ex: if there are 3 players i have to show the marble tht he is using, his score and his name ( for each player )

                    what i have currently done is :
                    i am geeting d no. of players connected say N .....then making a for loop - running it N times to make a grid where i show the marble tht he is using, his score and his name ( for each player )

                    the problem is to show the images of the marble ....i thought of making an array of imageicons , but it doesnt seem to support

                    i'll show u d part of the code
                    Code:
                     ImageIcon imgmarble[]={"player1.jpg","player2.jpg","player3.jpg","player4.jpg"};
                    		for(int i=0;i<n;i++)
                    		{
                    			
                    			lblcolor = new JLabel(imgmarble[i]);
                    			
                    			lblname = new JLabel("Player "+ (i+1));
                    			lblmoney = new JLabel("$300");
                    						
                    			lblname.setFont(font);
                    			lblmoney.setFont(font);
                    			
                    			pnlscore.add(lblcolor);
                    			pnlscore.add(lblname);
                    			pnlscore.add(lblmoney);
                    		}
                    and the kind of error i am getting is as follows :

                    C:\MainBoard1.j ava:57: incompatible types
                    found : java.lang.Strin g
                    required: javax.swing.Ima geIcon
                    ImageIcon imgmarble[]={"player1.jpg" ,"player2.jpg," player3.jpg","p layer4.jpg"};

                    how do i overcome it ???

                    Kind regards,
                    Malavika

                    Comment

                    • JosAH
                      Recognized Expert MVP
                      • Mar 2007
                      • 11453

                      #11
                      Originally posted by malavikarane
                      Code:
                       ImageIcon imgmarble[]={"player1.jpg","player2.jpg","player3.jpg","player4.jpg"};
                      and the kind of error i am getting is as follows :

                      C:\MainBoard1.j ava:57: incompatible types
                      found : java.lang.Strin g
                      required: javax.swing.Ima geIcon
                      ImageIcon imgmarble[]={"player1.jpg" ,"player2.jpg," player3.jpg","p layer4.jpg"};

                      how do i overcome it ???

                      Kind regards,
                      Malavika
                      Well a String isn't an ImageIcon; I agree with the compiler. Try to find a way to
                      load those ImageIcons given the Strings and put those in your array. You managed
                      to draw images somewhere previously and you must've created those ImageIcons
                      given some names so this shouldn't be a new problem to you.

                      kind regards,

                      Jos

                      Comment

                      Working...