Results 1 to 6 of 6

Thread: Waiting for mouse click event

  1. #1
    Join Date
    Dec 2009
    Posts
    202

    Waiting for mouse click event

    Hello,
    I have done a code to handle the moues click event, but unfortunately the code does not work and it is always waiting for the mouse click event.
    Here is my code, any advice.
    Code:
    class myclass {
    ...
    for (i =0 ; I <files.length ; I + +)
    	{
    	...
    	while ( ! Continue ) ;  / / Blocks until I response
    	}
    ...
     
     
    private void CreerIHM()
    {
    ...
    bnt = new JButton("OK") ;
    bnt.setEnabled(false) ;
    bnt.addActionListener( new ActionListener()
    	{
    	Public void actionPerformed(ActionEvent e)
    		{
    		...
    		Continue = true ;
    		...
    		}
    	}) ;
    ...
    }

  2. #2
    Join Date
    Nov 2009
    Posts
    343

    Re: Waiting for mouse click event

    Hello,
    Why not put the code that comes after
    Code:
    while ( ! Continue ) ;
    in Method ActionPerformed and if the calculation or transaction that takes time, you can create a Thread. I think it is better if you are using threads in your code and they will have lot more control over the program.

  3. #3
    Join Date
    Dec 2009
    Posts
    192

    Re: Waiting for mouse click event

    Hello,
    A question, what are you using to do the code that is the swing or the awt components ? If so, you didn't need to do this while (continue), Simply tone button with its ActionListener await the event. I do not really see where the problem lies. This is going to be easy for you if you are using the awt components.

  4. #4
    Join Date
    Nov 2009
    Posts
    347

    Re: Waiting for mouse click event

    Hello,
    You can try the following code.
    Code:
    myclass {
    Object o;
    ...
    for (i =0 ; I <files.length ; I + +)
    	{
    	...
    	synchronized(o)
           {
              o.wait();/ / Blocks until I response
           }  
    }
    ...
     
     
    private void CreerIHM()
    {
    ...
    bnt.addActionListener( new ActionListener()
    	{
    	Public void actionPerformed(ActionEvent e)
    		{
    		...
    		synchronized(o)
                    {
                       o.notify();/ / I releases
                    }  
    		...
    		}
    	}) ;
    ...
    }

  5. #5
    Join Date
    Dec 2009
    Posts
    202

    Re: Waiting for mouse click event

    Hello,
    It's great it works. Thank you very much. The problem is that my loop waiting for validation to download and display the new object. The AcionPerformed captures the event and running. Thanks for the replies and if you have any alternate solution or method for doing the same that for the same output then please post back with the same I am the interested one here. Thank in advance.

  6. #6
    Join Date
    Dec 2009
    Posts
    211

    Re: Waiting for mouse click event

    Hey
    I am new to swing components and the awt, but I have tried a code see if this helps you
    Code:
    public synchronized void stratc(){
    apan.addMouseListener(this);
    this.addMouseListener(this);
    while(rmvsta == 0){
    try{
    Thread.sleep(50);
    System.out.println("Sleeping.");
    }
    catch (InterruptedException e) {
    System.out.println("Interrupted.");
    }
    }
    System.out.println("leaving while loop .");
    }

Similar Threads

  1. How to handle JButton Click Event in Java Swing
    By Kungfu Pandey in forum Software Development
    Replies: 3
    Last Post: 20-01-2012, 12:13 PM
  2. Replies: 7
    Last Post: 22-12-2011, 05:56 AM
  3. Replies: 6
    Last Post: 12-06-2010, 05:26 AM
  4. on click event
    By Daren in forum Software Development
    Replies: 3
    Last Post: 06-03-2009, 03:47 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,529,792.18392 seconds with 17 queries