Hi A. Murat

Well, I think the code below can help you.

import java.awt.event.*;
import java.util.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import javax.swing.*;
import com.sun.j3d.utils.universe.*;

public class Example extends JFrame
{
        
        public Example()
        {
                addWindowListener(new WindowAdapter() {
                        public void windowClosing(WindowEvent e) {
                                dispose();
                                System.exit(0);
                        }
                });
                
                JButton b1 = new JButton("Behavior");
                getContentPane().setLayout(null);
                getContentPane().add(b1);
                b1.setBounds(10,10,100,50);
                
                final SimpleUniverse su = new SimpleUniverse();
                
                b1.addActionListener(new ActionListener()
                                                                {
        
public void actionPerformed(ActionEvent e)
                                                                        {
        
ButtonBehavior bBehavior = new
ButtonBehavior(su.getViewingPlatform().getViewPlatformTransform());
        
bBehavior.setSchedulingBounds(new BoundingSphere(new
Point3d(0.0,0.0,0.0),Double.POSITIVE_INFINITY));
        

        
BranchGroup branchBehavior = new BranchGroup();
        
branchBehavior.addChild(bBehavior);
        
su.getLocale().addBranchGraph(branchBehavior);
                                                                        }
                                                                });
        }

        public static void main(String args[])
        {
                Example mainFrame = new Example();
                mainFrame.setSize(130,90);
                mainFrame.setTitle("Example");
                mainFrame.setVisible(true);
        }
}

class ButtonBehavior extends Behavior
{
        TransformGroup tg;
        Transform3D c = new Transform3D();
        WakeupCriterion actionEvent;
        
    public ButtonBehavior(TransformGroup transformGroup)
    {
                tg = transformGroup;
    }

    public void initialize()
    {
                actionEvent = new
WakeupOnBehaviorPost(this,MouseEvent.MOUSE_CLICKED);
                postId(MouseEvent.MOUSE_CLICKED);
            wakeupOn(actionEvent);
    }

    public void processStimulus(Enumeration criteria)
    {
                System.out.println("It's working...");
                wakeupOn(actionEvent);
    }
}

-----Mensagem original-----
De: A. Murat Tanyer [mailto:[EMAIL PROTECTED] 
Enviada em: segunda-feira, 17 de mar�o de 2003 11:24
Para: [EMAIL PROTECTED]
Assunto: Re: [JAVA3D] help

  Hi Alessandro,

Thanks for your reply,

I understand that my use of switch is not the correct way. I will change
it according to your advices. However, my question is how I can link my
behaviour with the JButton event so that the cubes are woke up when I
press the button? At the moment the cubes woke up 3 seconds after the
scene construction.

I think I have to have two criteria for this; first is the elapsed time
the other is the press event of the JButton. But how can I detect that
the particular Button is pressed?

Regards,
Murat



Alessandro Borges wrote:

> Murat,
>
> You can use only one Switch to show  the cubes you want by using
>
> setChildMask(java.util.BitSet childMask)
> were childMask is a  java.util.BitSet object (see javadocs).
>
> By using it you can select correctly what will appear or not.
> Use constans to label your TGs
>
>
>     BG
>      |
>     SW
>  /   |   \
> TG1 TG2 TG3
>
>
> // use same sequence you add to switch
> int TG1_BIT = 01;
> int TG2_BIT = 02;
> int TG3_BIT = 03;
>
>
> BitSet mask = new BitSet();
> ...
> Swich switch = new Switch();
> switch.setWhichChild(Switch.CHILD_MASK);
> ...
> //to show TG1
> mask = switch.getChildMask();
> mask.set(TG1_BIT);
> switch.setChildMask(mask);
>
> // to show TG2, no show Tg3, show TG1
> mask = switch.getChildMask();
> mask.set(TG1_BIT);
> mask.set(TG2_BIT);
> mask.clear(TG3_BIT);
>
>
> I did not test above code, but I use a "look alike" one in a demo.
>
> Alessandro
>
>
>     ----- Original Message -----
>     From: A. Murat Tanyer <mailto:[EMAIL PROTECTED]>
>     To: [EMAIL PROTECTED]
>     <mailto:[EMAIL PROTECTED]>
>     Sent: Monday, March 17, 2003 9:12 AM
>     Subject: [JAVA3D] help
>
>     Dear all,
>
>     I am working on a small test program. I have three ColorCubes in
>     my scene, all attached to different switches (see attached for the
>     scenegraph). I am rendering only the first of these cubes by the
>     switch statements.
>
>     I want to wakeup the other two cubes three seconds after I press
>     the button on the GUI. I created a time behaviour class which uses
>     WakeupOnElapsedTime(3000). But the problem is that the cubes are
>     woke up three seconds after the scene is constructed. How can I
>     link my behaviour with the JButton event so that the cubes are
>     woke up when I press the button?
>
>     Thanks
>
>
>
>     public void initialize()
>     {
>     System.out.println("INITIALIZED");
>     critter = new WakeupOnElapsedTime(3000);
>     resetEvents();
>     }
>
>     protected final void resetEvents()
>     {
>     wakeupOn(critter);
>     }
>
>     // protected abstract void processAWTEvent(AWTEvent evt);
>
>     public void processStimulus(Enumeration criteria)
>     {
>     System.out.println("RUNNING PROCESS STIMULUS");
>     WakeupCondition cond;
>
>     while(criteria.hasMoreElements())
>     {
>     cond = (WakeupCondition)criteria.nextElement();
>     if(cond instanceof WakeupOnElapsedTime)
>     {
>     System.out.println("WAKE UP");
>
>     Switch1.setWhichChild(Switch.CHILD_NONE);
>     Switch2.setWhichChild(Switch.CHILD_ALL);
>     Switch3.setWhichChild(Switch.CHILD_ALL);
>     }
>     }
>     }
>
------------------------------------------------------------------------
>
>
------------------------------------------------------------------------
>

==========================================================================To 
unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to