This site requires JavaScript, please enable it in your browser!
Greenfoot back
rakesh8015
rakesh8015 wrote ...

2014/9/12

help me...

rakesh8015 rakesh8015

2014/9/12

#
import greenfoot.*; public class obj1 extends Actor { public void act() { if(Greenfoot.mousePressed(this)) { System.out.println("First click execution"); if(Greenfoot.mousePressed(this)) { System.out.println("second click execution "); } } } }
rakesh8015 rakesh8015

2014/9/12

#
is this possible to create????...on the first click "First click execution" must be printed and on second click "Second click execution" must be printed...
danpost danpost

2014/9/12

#
Please, please. Use code tags when posting code. Refer to the "Posting code? read this!" link below the 'Post a reply' box.
rakesh8015 rakesh8015

2014/9/12

#
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class obj1 here. * * @author (your name) * @version (a version number or a date) */ public class obj1 extends Actor { /** * Act - do whatever the obj1 wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if(Greenfoot.mousePressed(this)) { System.out.println("First click execution"); if(Greenfoot.mousePressed(this)) { System.out.println("second click execution "); } } } }
rakesh8015 rakesh8015

2014/9/12

#
you mean like this????....i am sorry..i am very new to greenfoot...
danpost danpost

2014/9/12

#
rakesh8015 wrote...
you mean like this????....i am sorry..i am very new to greenfoot...
No. Like this:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class obj1 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class obj1 extends Actor
{
    /**
     * Act - do whatever the obj1 wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        if(Greenfoot.mousePressed(this))
        {
            System.out.println("First click execution");
            if(Greenfoot.mousePressed(this))
            {
                System.out.println("second click execution ");
            }
        }
    }    
}
Click on the underlined 'Quote' to the left of this post to see how the code is enclosed with code tags. If you cannot copy your code and insert it in the pop-up that is supplied when clicking on the 'code' link below the 'Post a reply' box, then key the code tags in manually.
danpost danpost

2014/9/12

#
What exactly are you trying to accomplish with this obj1 object? That is, exactly what mouse states are you trying to detect? (be specific and thorough) I know the mouse needs to be on the object and at least one mouse button is to be pressed. I just do not know whether the second button press is to be from a different mouse button or you are trying to detect a double-click or just two individual clicks or what.
rakesh8015 rakesh8015

2014/9/12

#
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class obj1 here. * * @author (your name) * @version (a version number or a date) */ public class obj1 extends Actor { /** * Act - do whatever the obj1 wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if(Greenfoot.mousePressed(this)) { System.out.println("First click execution"); } if(Greenfoot.mousePressed(this)) { System.out.println("second click execution "); } } }
rakesh8015 rakesh8015

2014/9/12

#
on the first click "First click execution" must be printed and on second click "Second click execution" must be printed...
danpost danpost

2014/9/12

#
First, if you are checking for clicks, you should be using 'mouseClicked', not 'mousePressed'. Second, you will need an instance field (either boolean or int type) to change its value of when the first click is detected. Your detections will need two conditions each using the value of the field and detecting the click. After the second click, is the functionality supposed to revert back to its original state (where the next click will print "First click execution" to the terminal again)?
You need to login to post a reply.