Hi to all,
I have implemented the thing i needed succesfully, I’d like to share the logic with you guys as well , so following is the code snippet of my application :-
public VisualizerCameraBehavior() {
WakeupOnAWTEvent wakeuponawtevent = new WakeupOnAWTEvent(33L);
WakeupOnAWTEvent wakeuponawtevent1 = new WakeupOnAWTEvent(16L);
WakeupOnAWTEvent wakeuponawtevent2 = new WakeupOnAWTEvent(8L);
WakeupOnElapsedFrames wakeuponelapsedframes = new WakeupOnElapsedFrames(0);
bothCondition = new WakeupOr(new WakeupCriterion[] {
wakeuponawtevent, wakeuponawtevent1, wakeuponawtevent2, wakeuponelapsedframes
});
awtCondition = new WakeupOr(new WakeupCriterion[] {
wakeuponawtevent, wakeuponawtevent1, wakeuponawtevent2
});
}
public void processStimulus(Enumeration enumeration) {
while(enumeration.hasMoreElements())
{
WakeupCondition wakeupcondition = (WakeupCondition)enumeration.nextElement();
if(wakeupcondition instanceof WakeupOnAWTEvent)
{
processAWTEvents(((WakeupOnAWTEvent) wakeupcondition).getAWTEvent());
}
else if(wakeupcondition instanceof WakeupOnElapsedFrames)
{
/// do what you want to do. Move the camera on values calulated in processmouseevent() func
}
if(motion)
wakeupOn(bothCondition);
else
wakeupOn(awtCondition);
}
private void processAWTEvents(AWTEvent aawtevent[])
{
for(int i = 0; i < aawtevent.length; i++)
{
if(aawtevent[i] instanceof MouseEvent)
{
if((aawtevent[i].getID() == 506 || aawtevent[i].getID() == 501 || aawtevent[i].getID() == 502) /&& !ignoreMouseMotion/)
{
processMouseEvent((MouseEvent)aawtevent[i]);
}
}
}
protected void processMouseEvent(MouseEvent mouseevent)
{
float XValue = (float)mouseevent.getX();
float YValue = (float)mouseevent.getY();
if(SwingUtilities.isLeftMouseButton(mouseevent))
{
if(mouseevent.getID() == 502)
{
motion = false;
m_Movement = false;
} else
{
motion = true;
m_Movement = true;
// calculate and decide the direction of movement on basis of Xvalue and YValue
}
}