1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

2D Arrays

Discussion in 'Java' started by Ahovking, Apr 8, 2010.

  1. Ahovking

    Ahovking New Member

    Joined:
    Apr 8, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Declare a 2 dimentional array to store the x co-ordinates of every left mouse click (lmb),
    then when array is full print out all the stored values on the screen in a 10x10 matrix.


    do i have it right so for and i cant work out this last part
    plz help :)

    this is what i have so far

    Code:
    [COLOR=Red]import java.awt.*;
    import java.applet.*;
    import java.awt.event.*
    
    public class TwoDDrray extends Applet implements MouseListener{
    
        int[] lmb[10,10];
        int d1 = 0
        int d2 = 0
    
        public TwoDDrray()
        {
            addMouseListener ( this ) ;
    
            setBackground (java.awt.Color.blue ) ;
        }
    
        public void mouseClicked( MouseEvent ev ) {
    
        do{
            if (d2<9)
                d2++;
            eles (
                set d2=0
                d1++;
                    )
    
              }while (counter < 9);
        }
    
               if (d1<9)
            {
            lmb[d1][d2] = ev.getX();
            repaint ();
            }
           
            eles[/COLOR]
           [COLOR=Navy] Print out all the stored values ?          [/COLOR]
    }
     
    Last edited by a moderator: Apr 8, 2010
  2. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    fist of all it is not eles but else

    and int[][] lmb=new int[10][10];

    where to you declare counter variable?
     
  3. Ahovking

    Ahovking New Member

    Joined:
    Apr 8, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Well sorry im still a noob to this java thing lol

    initialise d1, d2 to 0
    declare lmb array[10][10]
    WHEN left mouse is clicked
    IF(d2<9)
    add 1 to d2
    ELSE
    set d2 to 0
    add 1 to d1

    IF(d1<9)
    set lmb[d1][d2] to x-coordinate of mouse event
    ELSE
    print out all the stored values
     

Share This Page