Results 1 to 7 of 7
  1. #1
    Laythe's Avatar
    Laythe is offline Member
    Join Date
    Mar 2009
    Posts
    28
    Rep Power
    0

    Question How to make a MouseListener Method to do multy tasks?

    Hello EveryOne :)

    This the code i am working on:
    Java Code:
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    
    public class MiniLudo extends Applet implements MouseListener,
                                                                MouseMotionListener
    {
        int playerone   [][] = new int [45][6];
    
        int roll;
        int Counter;
        int xPos;
        int yPos;
        int XPos;
        int YPos;
        int winner;
        int picNumber;
    
        boolean oneturn;
        boolean gameWon;
        boolean counterMoved;
        boolean Pressed;
    
        Image img, img1, img2, img3, img4, img5, img6,
              img7, img8, img9, img10, img11, img12, img13;
    
       public void init()
       {
            setSize(650,600);
            fillarray();
            playerone[0][2] = 1;
            Counter = 0;
            addMouseListener(this);
            winner = 0;
            counterMoved = true;
            Pressed = false;
            picNumber = 0;
       }
    
       public void paint (Graphics graf)
        {
            img   = getImage(getCodeBase(), "square.JPG");
            img1  = getImage(getCodeBase(), "red.JPG");
            img2  = getImage(getCodeBase(), "center.JPG");
            img3  = getImage(getCodeBase(), "dice3.JPG");
            img4  = getImage(getCodeBase(), "roll sign.JPG");
            img5  = getImage(getCodeBase(), "one4.JPG");
            img6  = getImage(getCodeBase(), "two4.JPG");
            img7  = getImage(getCodeBase(), "three4.JPG");
            img8  = getImage(getCodeBase(), "four4.JPG");
            img9  = getImage(getCodeBase(), "five4.JPG");
            img10 = getImage(getCodeBase(), "six4.JPG");
            img11 = getImage(getCodeBase(), "gameover4.JPG");
            img12 = getImage(getCodeBase(), "onewin4.JPG");
            img13 = getImage(getCodeBase(), "redstart.JPG");
    
            //------------------- draw gridd ------------------------------------//
            for(int i=0; i<=39; i++)
            {
                graf.drawImage(img, playerone[i][0], playerone[i][1], this);
            }
    
            //------------------- draw red gridd -------------------------------//
            for(int i=40; i<=43; i++)
            {
                graf.drawImage(img1, playerone[i][0], playerone[i][1], this);
            }
    
            graf.drawImage(img2, 300, 300, this);
            graf.drawImage(img13, 50, 250, this);
    
            if(gameWon == false)
            {
                graf.drawImage(img3, 450, 100, this);
            }
    
            if(counterMoved == false)
            {
                graf.drawImage(img4, 400, 400, this);
            }
            
            if(picNumber == 1)
            {
                graf.drawImage(img4, 400, 400, this);
            }
    
            //------------------- start draw counters ---------------------------//
            for (int i=0; i<=43; i++)
            {
                if(playerone[i][3] == 1 & counterMoved == false)
                {
                    graf.setColor(Color.red);
                    graf.fillOval(playerone[i][0] + 10, playerone[i][1] + 10,30,30);
                }
                if(playerone[i][2] == 1 & counterMoved == true)
                {
                    graf.setColor(Color.red);
                    graf.fillOval(playerone[i][0] + 10, playerone[i][1] + 10,30,30);
                }
            }
            //------------------- end draw counters ----------------------------//
    
            //----------------------  start Draw dice roll ---------------------//
            if(roll == 1)
            {
                graf.drawImage(img5, 450, 455, this);
            }
            if(roll == 2)
            {
                graf.drawImage(img6, 450, 455, this);
            }
            if(roll == 3)
            {
                graf.drawImage(img7, 450, 455, this);
            }
            if(roll == 4)
            {
                graf.drawImage(img8, 450, 455, this);
            }
            if(roll == 5)
            {
                graf.drawImage(img9, 450, 455, this);
            }
            if(roll == 6)
            {
                graf.drawImage(img10, 450, 455, this);
            }
            //---------------------- end Draw dice roll ------------------------//
    
            //---------------------- start display winner ----------------------//
            if(winner == 1 & counterMoved == true)
            {
                graf.drawImage(img12, 50, 425, this);
            }
            
    
            if(gameWon == true & counterMoved == true)
            {
                graf.drawImage(img11, 450, 100, this);
                graf.setColor(Color.white);
                graf.fillRect(400,400,400,400);
                picNumber = 0;
            }
            //---------------------- end display winner ------------------------//
       }
    
       //---------------------- start Create grid ------------------------------//
        public void fillarray()
        {
            int xCoord = 50;
            int yCoord = 250;
    
            for(int i=0; i<=4; i++)
            {
                playerone[i][0] = xCoord;
                playerone[i][1] = yCoord;
    
                xCoord = xCoord + 50;
            }
    
            yCoord = yCoord - 50;
            xCoord = xCoord - 50;
            for(int i=5; i<=8; i++)
            {
                playerone[i][0] = xCoord;
                playerone[i][1] = yCoord;
    
                yCoord = yCoord - 50;
            }
    
            playerone[9][0] = 300;
            playerone[9][1] = 50;
    
    
            yCoord = 50;
            xCoord = 350;
            for(int i=10; i<=14; i++)
            {
                playerone[i][0] = xCoord;
                playerone[i][1] = yCoord;
    
                yCoord = yCoord + 50;
            }
    
            yCoord = 250;
            xCoord = 400;
            for(int i=15; i<=18; i++)
            {
                playerone[i][0] = xCoord;
                playerone[i][1] = yCoord;
    
                xCoord = xCoord + 50;
            }
    
            playerone[19][0] = 550;
            playerone[19][1] = 300;
    
    
            xCoord = 550;
            yCoord = 350;
            for(int i=20; i<=24; i++)
            {
                playerone[i][0] = xCoord;
                playerone[i][1] = yCoord;
    
                xCoord = xCoord - 50;
            }
    
            xCoord = 350;
            yCoord = 400;
            for(int i=25; i<=28; i++)
            {
                playerone[i][0] = xCoord;
                playerone[i][1] = yCoord;
    
                yCoord = yCoord + 50;
            }
    
            playerone[29][0] = 300;
            playerone[29][1] = 550;
    
    
            xCoord = 250;
            yCoord = 550;
            for(int i=30; i<=34; i++)
            {
                playerone[i][0] = xCoord;
                playerone[i][1] = yCoord;
    
                yCoord = yCoord - 50;
            }
    
            xCoord = 200;
            yCoord = 350;
            for(int i=35; i<=38; i++)
            {
                playerone[i][0] = xCoord;
                playerone[i][1] = yCoord;
    
                xCoord = xCoord - 50;
            }
    
            playerone[39][0] = 50;
            playerone[39][1] = 300;
    
    
            xCoord = 100;
            yCoord = 300;
            for(int i=40; i<=44; i++)
            {
                playerone[i][0] = xCoord;
                playerone[i][1] = yCoord;
                xCoord = xCoord + 50;
            }
        }
        //---------------------- end Create grid --------------------------------//
    
    
        //----------------- star MouseListener Methods --------------------------//
        private void setValues (int x, int y)
        {
            xPos = x;
            yPos = y;
        }
    
        private void setvalues (int x, int y)
        {
            XPos = x;
            YPos = y;
            rollDice();
            repaint();
        }
    
        public void mouseClicked(MouseEvent e)
        {
        }
    
        public void mousePressed(MouseEvent e)
        {
            setValues(e.getX(), e.getY() );
        }
    
        public void mouseReleased(MouseEvent e)
        {
            setvalues(e.getX(), e.getY() );
        }
    
        public void mouseEntered(MouseEvent e)
        {
        }
    
        public void mouseExited(MouseEvent e)
        {
        }
    
        public void mouseDragged(MouseEvent e)
        {
        }
    
        public void mouseMoved(MouseEvent e)
        {
        }
        //----------------- end MouseListener Methods --------------------------//
    
    
        //----------------- star rollDice Method ------------------------------//
        public void rollDice()
        {
            if (xPos >= 450 & xPos <= 550 & yPos >= 100 & yPos <= 200)
            {
                if(Counter == 0)
                {
                    for(int i=0; i<playerone.length; i++)
                    {
                        playerone[i][3] = 0;
                        if(playerone[i][2] == 1)
                        {
                            playerone[i][3] = 1;
                        }
                    }
    
    
                    //-------------------- Making the move -------------------------
    
                    roll = 1 + (int)(Math.random() * 6);
                    picNumber = 1;
                    oneturn = true;
                    for(int i=39; i<45; i++)
                    {
                        if (playerone[39][2] == 1)
                        {
                            if (roll<6)
                            {
                                playerone[39][2] = 0;
                                playerone[39+roll][2] = 1;
                                if(gameWon == false)
                                {
                                    counterMoved = false;
                                }
                            }
                            oneturn = false;
                        }
                        else
                        if (playerone[40][2] == 1 & oneturn == true)
                        {
                            if (roll<5)
                            {
                                playerone[40][2] = 0;
                                playerone[40+roll][2] = 1;
                                if(gameWon == false)
                                {
                                    counterMoved = false;
                                }
                            }
                            oneturn = false;
                        }
                        else
                        if (playerone[41][2] == 1 & oneturn == true)
                        {
                            if (roll<4)
                            {
                                playerone[41][2] = 0;
                                playerone[41+roll][2] = 1;
                                if(gameWon == false)
                                {
                                    counterMoved = false;
                                }
                            }
                            oneturn = false;
                        }
                        else
                        if (playerone[42][2] == 1 & oneturn == true)
                        {
                            if (roll<3)
                            {
                                playerone[42][2] = 0;
                                playerone[42+roll][2] = 1;
                                if(gameWon == false)
                                {
                                    counterMoved = false;
                                }
                            }
                            oneturn = false;
                        }
                        else
                        if (playerone[43][2] == 1 & oneturn == true)
                        {
                            if (roll<2)
                            {
                                playerone[43][2] = 0;
                                playerone[43+roll][2] = 1;
                                if(gameWon == false)
                                {
                                    counterMoved = false;
                                }
                            }
                            oneturn = false;
                        }
                        else
                        if (playerone[44][2] == 1 & oneturn == true)
                        {
                            oneturn = false;
                        }
                    }
                    if(oneturn == true)
                    {
                        for(int i=43; i>=0; i--)
                        {
                            if (playerone[i][2] == 1)
                            {
                                playerone[i][2] = 0;
                                playerone[i+roll][2] = 1;
                                if(gameWon == false)
                                {
                                    counterMoved = false;
                                }
                            }
                        }
                    }
    
                    if(counterMoved == false)
                    {
                        Counter = 5;
                    }
                }
            }
    
            if(Counter == 5)
            {
                for(int i=0; i<playerone.length; i++)
                {
                    if(playerone[i][3] == 1)
                    {
                        if(xPos >= playerone[i][0] & xPos <= playerone[i][0]+50 & yPos >= playerone[i][1] & yPos <= playerone[i][1]+50)
                        {
                          Pressed = true;
                        }
                    }
                    if(playerone[i][2] == 1)
                    {
                        if(XPos >= playerone[i][0] & XPos <= playerone[i][0]+50 & YPos >= playerone[i][1] & YPos <= playerone[i][1]+50)
                        {
                          counterMoved = true;
                          Pressed = false;
                          Counter = 0;
                        }
                    }
                }
            }
    
            if(playerone[44][2] == 1 & winner == 0)
            {
                winner = 1;
            }
    
            if(playerone[44][2] == 1)
            {
                gameWon = true;
                counterMoved = true;
            }
        }
        //----------------- end rollDice Method --------------------------------//
    }


    First I dont understand the diffrence between xPos, yPos and XPos, YPos.

    Second, what i need to do is:
    when i roll the dice the counter shouldn't mouve till i click on it first then click on where it should be moved.

    I tried alot of ways to solve this but i still dont hit the right spot,
    this is one of the things i tried:
    Java Code:
    public void mousePressed(MouseEvent e)
        {
            setValues(e.getX(), e.getY() );
    
            int X = e.getX();
            int Y = e.getY();
    
            for(int i=0; i<playerone.length; i++)
            {
                    if(playerone[i][3] == 1)
                    {
                        if(X >= playerone[i][0] & X <= playerone[i][0]+30 & Y >= playerone[i][1] & Y <= playerone[i][1]+30)
                        {
                          Pressed = true;
                        }
                    }
                    if(playerone[i][2] == 1)
                    {
                        if(XPos >= playerone[i][0] & XPos <= playerone[i][0]+50 & YPos >= playerone[i][1] & YPos <= playerone[i][1]+50)
                        {
                          counterMoved = true;
                          Pressed = false;
                          Counter = 0;
                        }
                    }
            }
        }
    I almost forgot this is the graphics you will need for the game.
    the graphics are attached to the thread.

    Please Help.
    Attached Files Attached Files
    Last edited by Laythe; 12-09-2009 at 08:05 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    That's a heck of a lot of code to ask anyone to go through. Perhaps someone will go through it all, but if they don't, you'll probably want to create an SSCCE which will be a much smaller compilable program that demonstrates your problem but is of much more reasonable size. Also, you really don't want to read in image files from within a paint method. This will slow your graphics to a crawl. Why not just read in the images once during the init method rather than re-read the images every time your program wants to repaint the screen?
    Last edited by Fubarable; 12-09-2009 at 04:46 AM.

  3. #3
    Laythe's Avatar
    Laythe is offline Member
    Join Date
    Mar 2009
    Posts
    28
    Rep Power
    0

    Default

    Thank you sir Fubarable for your reply,
    you are right the code is long but i already omitted all the unnecessary lines from the code, but i will try to shrink it more.

    Also, you really don't want to read in image files from within a paint method. This will slow your graphics to a crawl. Why not just read in the images once during the init method rather than re-read the images every time your program wants to repaint the screen?
    Good point of view, thank for the tip i will consider it in my coding.

  4. #4
    Laythe's Avatar
    Laythe is offline Member
    Join Date
    Mar 2009
    Posts
    28
    Rep Power
    0

    Default

    After folowing your advice i made a shrinked version of the code, and i remebered what's the diffrence between xPos, yPos and XPos, YPos.
    xPos, yPos are used to set the zone where the player should click to roll the dice; XPos, YPos are used to set to range that may be clicked for the counter to move.

    The shrinked version:
    Java Code:
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    
    public class MiniLudo2 extends Applet implements MouseListener,
                                                                MouseMotionListener
    {
        int playerone   [][] = new int [45][6];
    
        int roll;
        int Counter;
        int xPos;
        int yPos;
        int XPos;
        int YPos;
    
        boolean oneturn;
        boolean counterMoved;
        boolean Pressed;
    
        Image img1, img2, img3, img4, img5, img6, img7;
        
        public void init()
        {
            setSize(650,600);
            fillarray();
            playerone[0][2] = 1;
            Counter = 0;
            addMouseListener(this);
            counterMoved = true;
            Pressed = false;
    
            img1  = getImage(getCodeBase(), "square.JPG");
            img2  = getImage(getCodeBase(), "redstart.JPG");
            img3  = getImage(getCodeBase(), "dice3.JPG");
            img4  = getImage(getCodeBase(), "roll sign.JPG");
            img5  = getImage(getCodeBase(), "one4.JPG");
            img6  = getImage(getCodeBase(), "two4.JPG");
            img7  = getImage(getCodeBase(), "three4.JPG");
        }
    
        public void paint (Graphics graf)
       {
    
    
            //------------------- draw gridd ------------------------------------//
            for(int i=0; i< 16; i++)
            {
                graf.drawImage(img1, playerone[i][0], playerone[i][1], this);
            }
    
            graf.drawImage(img2, 200, 150, this);
    
            graf.drawImage(img3, 450, 300, this);
            
            
    
            if(counterMoved == false)
            {
                graf.drawImage(img4, 400, 400, this);
            }
    
            //------------------- start draw counters ---------------------------//
            for (int i=0; i<=43; i++)
            {
                if(playerone[i][3] == 1 & counterMoved == false)
                {
                    graf.setColor(Color.red);
                    graf.fillOval(playerone[i][0] + 10, playerone[i][1] + 10,30,30);
                }
                if(playerone[i][2] == 1 & counterMoved == true)
                {
                    graf.setColor(Color.red);
                    graf.fillOval(playerone[i][0] + 10, playerone[i][1] + 10,30,30);
                }
            }
            //------------------- end draw counters ----------------------------//
    
            //----------------------  start Draw dice roll ---------------------//
            if(roll == 1)
            {
                graf.drawImage(img5, 450, 455, this);
            }
            if(roll == 2)
            {
                graf.drawImage(img6, 450, 455, this);
            }
            if(roll == 3)
            {
                graf.drawImage(img7, 450, 455, this);
            }
            //---------------------- end Draw dice roll ------------------------//
        }
    
        //---------------------- start Create grid ------------------------------//
        public void fillarray()
        {
            int xCoord = 200;
            int yCoord = 150;
    
            for(int i=0; i< 5; i++)
            {
                playerone[i][0] = xCoord;
                playerone[i][1] = yCoord;
    
                xCoord = xCoord + 50;
            }
    
            xCoord = 400;
            yCoord = 200;
            for(int i=5; i < 9; i++)
            {
                playerone[i][0] = xCoord;
                playerone[i][1] = yCoord;
    
                yCoord = yCoord + 50;
            }
    
            xCoord = 350;
            yCoord = 350;
            for(int i=9; i < 13; i++)
            {
                playerone[i][0] = xCoord;
                playerone[i][1] = yCoord;
    
                xCoord = xCoord - 50;
            }
    
            xCoord = 200;
            yCoord = 300;
            for(int i=13; i < 17; i++)
            {
                playerone[i][0] = xCoord;
                playerone[i][1] = yCoord;
    
                yCoord = yCoord - 50;
            }
        }
    
    
        //----------------- star MouseListener Methods --------------------------//
        private void setValues (int x, int y)
        {
            xPos = x;
            yPos = y;
        }
    
        private void setvalues (int x, int y)
        {
            XPos = x;
            YPos = y;
            rollDice();
            repaint();
        }
    
        public void mouseClicked(MouseEvent e)
        {
        }
    
        public void mousePressed(MouseEvent e)
        {
            setValues(e.getX(), e.getY() );
        }
    
        public void mouseReleased(MouseEvent e)
        {
            setvalues(e.getX(), e.getY() );
        }
    
        public void mouseEntered(MouseEvent e)
        {
        }
    
        public void mouseExited(MouseEvent e)
        {
        }
    
        public void mouseDragged(MouseEvent e)
        {
        }
    
        public void mouseMoved(MouseEvent e)
        {
        }
        //----------------- end MouseListener Methods --------------------------//
    
        //----------------- star rollDice Method ------------------------------//
        public void rollDice()
        {
            if (xPos >= 450 & xPos <= 550 & yPos >= 300 & yPos <= 400)
            {
                if(Counter == 0)
                {
                    for(int i=0; i<playerone.length; i++)
                    {
                        playerone[i][3] = 0;
                        if(playerone[i][2] == 1)
                        {
                            playerone[i][3] = 1;
                        }
                    }
    
    
                    //-------------------- Making the move -------------------------
    
                    roll = 1 + (int)(Math.random() * 3);
    //                picNumber = 1;
                    oneturn = true;
                    
                    if(oneturn == true)
                    {
                        for(int i=16; i>=0; i--)
                        {
                            if (playerone[i][2] == 1)
                            {
                                playerone[i][2] = 0;
                                playerone[i+roll][2] = 1;
                                
                                    counterMoved = false;
    
                            }
                        }
                    }
    
                    if(counterMoved == false)
                    {
                        Counter = 5;
                    }
                }
            }
    
            if(Counter == 5)
            {
                for(int i=0; i<playerone.length; i++)
                {
                    if(playerone[i][3] == 1)
                    {
                        if(xPos >= playerone[i][0] & xPos <= playerone[i][0]+100 & yPos >= playerone[i][1] & yPos <= playerone[i][1]+100)
                        {
                          Pressed = true;
                        }
                    }
                    if(playerone[i][2] == 1)
                    {
                        if(XPos >= playerone[i][0] & XPos <= playerone[i][0]+100 & YPos >= playerone[i][1] & YPos <= playerone[i][1]+100)
                        {
                          counterMoved = true;
                          Pressed = false;
                          Counter = 0;
                        }
                    }
                }
            }
    
    
    
        }
        //----------------- star rollDice Method ------------------------------//
    }

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    There are a couple of ways to solve this. Unfortunately I understand Swing and not AWT, so I cannot give any advice on AWT specifics (other than I strongly recommend that you switch from AWT to Swing). Having said that, if this were Swing, I would consider making the dice button, well a JButton and set its ImageIcon to your dice image. Next I could use JLabels or JPanels for the game squares, each with their own MouseListener and with their own paintComponent method able to draw the disk.

    Another option is to refactor this class (I recommend this anyway as your class is WAY too big and unwieldy) and create a GameGrid class to encapsulate the idea of each cell or grid in the game. These grids would "know" their location, and you could iterate through a collection of them in the mouselistener checking to see if the mouse clicked within a grid square.

  6. #6
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    when i roll the dice the counter shouldn't mouve till i click on it first then click on where it should be moved
    You have to build up this kind of behavior slowly in your mouse code. Here's an example based on your applet code.
    Java Code:
    //  <applet code="MouseControl" width="500" height="500"></applet>
    //  use:>appletviewer MouseControl.java
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    
    public class MouseControl extends Applet {
        Point loc = new Point();
        Rectangle[] rects;
        final int SIZE = 50;
        // Flag used to control movement of loc.
        boolean haveFirstCell = false;
    
        public void init() {
            addMouseListener(ma);
        }
    
        public void paint(Graphics g) {
            if(rects == null) {
                initRects();
            }
            for(int i = 0; i < rects.length; i++) {
                g.setColor(Color.blue);
                ((Graphics2D)g).draw(rects[i]);
                g.setColor(Color.red);
                g.drawString(String.valueOf(i), rects[i].x+20, rects[i].y+30);
            }
            g.setColor(Color.green.darker());
            ((Graphics2D)g).setStroke(new BasicStroke(2f));
            int diam = SIZE/2;
            g.drawOval(loc.x-diam/2, loc.y-diam/2, diam, diam);
            g.setColor(Color.black);
            int h = getHeight();
            g.drawString("Click on the green circle and then on " +
                         "any other square", 50, h-25);
        }
    
        private void initRects() {
            int w = getWidth();
            int h = getHeight();
            int cellsPerSide = 5;
            int x0 = (w - cellsPerSide*SIZE)/2;
            int y0 = (h - cellsPerSide*SIZE)/2;
            int n = cellsPerSide -1;
            // Draw n cells for each of the 4 sides.
            rects = new Rectangle[4*n];
            int x = x0, y = y0;
            for(int i = 0; i < n; i++) {
                rects[i] = new Rectangle(x, y, SIZE, SIZE);
                y += SIZE;
            }
            for(int i = n; i < 2*n; i++) {
                rects[i] = new Rectangle(x, y, SIZE, SIZE);
                x += SIZE;
            }
            for(int i = 2*n; i < 3*n; i++) {
                rects[i] = new Rectangle(x, y, SIZE, SIZE);
                y -= SIZE;
            }
            for(int i = 3*n; i < 4*n; i++) {
                rects[i] = new Rectangle(x, y, SIZE, SIZE);
                x -= SIZE;
            }
            setLoc(0);
        }
    
        private void setLoc(int index) {
            int x = (int)rects[index].getCenterX();
            int y = (int)rects[index].getCenterY();
            loc.setLocation(x, y);
        }
    
        private MouseAdapter ma = new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
                Point p = e.getPoint();
                // Did the user click in/over a rectangle?
                for(int i = 0; i < rects.length; i++) {
                    if(rects[i].contains(p)) {
                        // Does this rectangle contain loc?
                        if(rects[i].contains(loc)) {
                            // Is this the first click over loc?
                            if(!haveFirstCell) {
                                haveFirstCell = true;
                            }
                        } else if(haveFirstCell) {
                            // We are in a rectangle that does not
                            // contain loc. If the flag haveFirstCell
                            // is true we can reset it and move loc
                            // to this rectangle.
                            haveFirstCell = false;
                            setLoc(i);
                            repaint();
                        }
                        break;
                    }
                }
            }
        };
    
        public static void main(String[] args) {
            MouseControl applet = new MouseControl();
            Frame f = new Frame();
            f.addWindowListener(closer);
            f.add(applet);
            f.setSize(500,500);
            f.setLocation(100,100);
            applet.init();
            f.setVisible(true);
        }
    
        private static WindowListener closer = new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        };
    }

  7. #7
    Laythe's Avatar
    Laythe is offline Member
    Join Date
    Mar 2009
    Posts
    28
    Rep Power
    0

    Default

    Thank you very very very much sir hardwired for the code, i'll study it and then try to use it in my code, if i get some problem i will poste it.
    Thank you again i was really lost, i really appreciate it :)
    Last edited by Laythe; 12-13-2009 at 04:01 AM.

Similar Threads

  1. Static method cannot make new objects?
    By zerkz in forum New To Java
    Replies: 2
    Last Post: 10-15-2009, 04:17 AM
  2. Use an internal Method or Make a class file?
    By TimHuey in forum New To Java
    Replies: 2
    Last Post: 09-18-2009, 04:06 PM
  3. Scheduling tasks using Threads
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-11-2007, 11:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •