Ron's Brain

Your ad here! KL4-7291
10 total messages. For real this time.
Gadolinium
04/12/2007 @ 16:49:18 EDT

Anyone know how to tell a specific thread in Java to wait? Right now I have a class that is creating two separate threads but my main executing thread keeps pausing because the wait() command pauses the current thread rather than the underling thread that I really want to wait.

Gadolinium
04/12/2007 @ 17:11:20 EDT

Never mind about that I found a slightly sneaky way around my problem.

Hydrogen
04/12/2007 @ 20:37:13 EDT

I'm curious about your slightly sneaky way, because those words make me nervous.

Gadolinium
04/12/2007 @ 21:03:13 EDT

Basically I just have some loops going until I decide to destroy it. I need to constantly update anyways. Oh might as well ask, do you know of a way to check directly if the mouse button is pressed in Java. I mean this in such a way that I could get a boolean answer even if the mouse is not clicking a Java component. Oh I also know that I'm not checking for a ton of problems that could arise but this is my basic thing.

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class SimpleThread extends Thread {
private int countDown = 5;
private static int threadCount = 0;
private int threadNumber = ++threadCount;
private boolean inbounds=false;
private boolean notDestroy=true;
Component component;
public SimpleThread(Component component) {
this.component=component;
}
public void run() {
try{while(notDestroy==true)
{
while (inbounds==false) {

System.out.println(MouseInfo.getPointerInfo().getLocation());

Thread.sleep(50);}
if(notDestroy==true)
{while (inbounds==true) {Thread.sleep(100);}}}

}catch(InterruptedException e){}
}
public void pause(){inbounds=true;}
public void restart(){inbounds=false;}
public void end(){notDestroy=false;}
}

Hydrogen
04/12/2007 @ 22:14:32 EDT

I don't know of a way to get a mouse event triggered on another object outside of the Java application. It's my guess that this isn't going to be possible, you'll have to bypass the system's event and message pump system, which usually requires specific OS related system calls, which isn't something within the scope of the Java language. I'm also curious what problem you're trying to solve that requires this type of thread. Or are you just screwing around with threads?

Gadolinium
04/12/2007 @ 22:29:45 EDT

Partially screwing around with threads and partially I'm trying to write an unseen logger. Also I'm trying to write a more usable demo robot in Java and what I'm trying to do is say where do you want the mouse to click kind of thing. How would you go about looking directly at if the mouse is pressed. All I know is c++ and Java so if ya know you could let me in on something that way it would be cool.

Hydrogen
04/12/2007 @ 22:55:39 EDT

Again, within the context of Java, I'm pretty sure you can't get mouse events outside of the application. With C++, you'll need to use system calls for whatever operating system you're doing this on, such as _TrackMouseEvent found in user32.dll on Windows.

I'm still not convinced that a thread is necessary for this, but as long as you're making this a learning experience, then, hey, what the hell.

Gadolinium
04/12/2007 @ 23:00:45 EDT

Well the reason I am using a thread is because I am also having another main program doing something else so instead of it being constantly locked into where is the mouse I used a thread. Or at least that was my reasoning. Probably very flawed. I do have an idea though do you know how to make a click able Java button without a frame?

Gadolinium
04/13/2007 @ 11:08:23 EDT

Never mind again. I found yet another tricky way around my problem. Lets hear it for forcing a high level language to do low level problems.

Strontium
04/13/2007 @ 12:42:00 EDT

You can't do that, its backwards from society.. high level people make low level people do their work. Thats how it goes.

Recent users
Logged on users that have pretended to enjoy this site within the last five minutes
There are no logged on users. How sad!