drag to rotate

D

Dan Barnet

Hi, I wrote my first "real" program in java.
It is a tictactoe game in 3D.
It seems to do what I want except for the dragging of the cube.
Right now the cube is not redrawn when I drag, only when I release the
mouse. I resorted to calculating a new cube display from the start-end
drag mouse positions.

How can I make the cube being redrawn "as I drag"?
The applet is at http://www.milinta.com/ttt3d.html

Thxs
 
C

Chris Smith

Dan said:
Hi, I wrote my first "real" program in java.
It is a tictactoe game in 3D.
It seems to do what I want except for the dragging of the cube.
Right now the cube is not redrawn when I drag, only when I release the
mouse. I resorted to calculating a new cube display from the start-end
drag mouse positions.

How can I make the cube being redrawn "as I drag"?
The applet is at http://www.milinta.com/ttt3d.html

Unfortunately, there's no code there. My guess is that there's
something interesting going on with your event handling. Presumably,
you add a MouseListener to the applet; what does that look like?

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
T

Thomas Weidenfeller

Dan said:
It seems to do what I want except for the dragging of the cube.
Right now the cube is not redrawn when I drag, only when I release the
mouse. I resorted to calculating a new cube display from the start-end
drag mouse positions.

Without the seeing the code one can only guess. Sound's like you didn't
understand how the Java GUI event handling works. Check Sun's GUI
tutorial, and check the comp.lang.java.gui FAQ.

/Thomas
 
C

Chris Uppal

Dan said:
It seems to do what I want except for the dragging of the cube.
Right now the cube is not redrawn when I drag, only when I release the
mouse. I resorted to calculating a new cube display from the start-end
drag mouse positions.

You have overridden mouseDrag() in your code, but if you look at the API docs,
you'll see that that is deprecated since Java 1.1, so it's not surprising that
it doesn't work. If you add a MouseMotionListener then it should work OK.
See:


<http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Component.html#addMouseMotion
Listener(java.awt.event.MouseMotionListener)>

In fact I suspect it's /really/ because the Component doesn't activate its
emulation of the deprecated APIs unless mouse motion events are activated.
That's why your override of the similarly deprecated mouseUp() "works" but
mouseDrag() doesn't. You could enable those events explicitly, but it looks a
lot easier just to go with the flow and do it "right" with a
MouseMotionListener.

-- chris
 
D

Dan Barnet

Chris Uppal said:
You have overridden mouseDrag() in your code, but if you look at the API docs,
you'll see that that is deprecated since Java 1.1, so it's not surprising that
it doesn't work. If you add a MouseMotionListener then it should work OK.

You (and everyone else) were right. My code was based on an older
example. It seems to be working better now altho it certainly could be
improved.
If you want to see what it now looks like check
www.milinta.com/ttt3d.html
/D
 
A

Andrew Thompson

If you want to see what it now looks like check
www.milinta.com/ttt3d.html

Nice. A few useability suggestions
for your further development.

Inform the user textually of a win or loss.
Perhaps also draw a new square to click
for 'new game'

I tried to click one square but missed
and another was highlit (I *swear* the pointer
was over the other one on the lower layer).
Perhaps you should 'pulse' the color of
the changing square for a few moments
before considering it 'set'. If the user
clicks any point on the board during
that 'pulsing' time, the selection is
cancelled.

HTH
 
D

Dan Barnet

Andrew Thompson said:
Nice. A few useability suggestions
for your further development.

Inform the user textually of a win or loss.
Perhaps also draw a new square to click
for 'new game'

I tried to click one square but missed
and another was highlit (I *swear* the pointer
was over the other one on the lower layer).
Perhaps you should 'pulse' the color of
the changing square for a few moments
before considering it 'set'. If the user
clicks any point on the board during
that 'pulsing' time, the selection is
cancelled.

That was a bug (fixed now I think). If I were to release this in the
wild (or if I had time) I'd make a few more changes. Right now I use
the browser's status line (not always ON I know) and the top line of
the applet to display messages.
Thanks for your feedback.
/D
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top