Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   2D Arrays (http://www.go4expert.com/forums/2d-arrays-t21699/)

Ahovking 8Apr2010 07:25

2D Arrays
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


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 ) {

        if (d2<9)
        eles (
            set d2=0

          }while (counter < 9);

          if (d1<9)
        lmb[d1][d2] = ev.getX();
        repaint ();

      Print out all the stored values ?         

virxen 8Apr2010 20:48

Re: 2D Arrays
fist of all it is not eles but else

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

where to you declare counter variable?

Ahovking 9Apr2010 07:39

Re: 2D Arrays
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
add 1 to d2
set d2 to 0
add 1 to d1

set lmb[d1][d2] to x-coordinate of mouse event
print out all the stored values

All times are GMT +5.5. The time now is 13:22.