當前位置: 首頁>>代碼示例>>Java>>正文


Java ActionListener類代碼示例

本文整理匯總了Java中com.jme3.input.controls.ActionListener的典型用法代碼示例。如果您正苦於以下問題:Java ActionListener類的具體用法?Java ActionListener怎麽用?Java ActionListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ActionListener類屬於com.jme3.input.controls包,在下文中一共展示了ActionListener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initInput

import com.jme3.input.controls.ActionListener; //導入依賴的package包/類
private void initInput(){
    getInputManager().addMapping("LEFT", new KeyTrigger(KeyInput.KEY_J));
    getInputManager().addMapping("RIGHT", new KeyTrigger(KeyInput.KEY_L));
    getInputManager().addMapping("UP", new KeyTrigger(KeyInput.KEY_I));
    getInputManager().addMapping("DOWN", new KeyTrigger(KeyInput.KEY_K));
    getInputManager().addMapping("JUMP", new KeyTrigger(KeyInput.KEY_SPACE));
    getInputManager().addListener((ActionListener) (name, isPressed, tpf) -> {
        Vector2f movement = new Vector2f();
        if(isPressed){
            switch (name) {
                case "LEFT": movement.setX(-1); break;
                case "RIGHT": movement.setX(+1); break;
                case "UP": movement.setY(-1); break;
                case "DOWN": movement.setY(+1); break;
            }
        }
        entityData.setComponent(character,  new PhysicsCharacterMovement(movement));
    }, "LEFT", "RIGHT", "UP", "DOWN");
    getInputManager().addListener((ActionListener) (name, isPressed, tpf) ->
            entityData.setComponent(character, new PhysicsCharacterState(isPressed, false)
    ), "JUMP");
}
 
開發者ID:jvpichowski,項目名稱:ZayES-Bullet,代碼行數:23,代碼來源:DynamicCharacterExample.java

示例2: initInput

import com.jme3.input.controls.ActionListener; //導入依賴的package包/類
private void initInput(){
    getInputManager().addMapping("LEFT", new KeyTrigger(KeyInput.KEY_J));
    getInputManager().addMapping("RIGHT", new KeyTrigger(KeyInput.KEY_L));
    getInputManager().addMapping("UP", new KeyTrigger(KeyInput.KEY_I));
    getInputManager().addMapping("DOWN", new KeyTrigger(KeyInput.KEY_K));
    getInputManager().addMapping("JUMP", new KeyTrigger(KeyInput.KEY_SPACE));
    getInputManager().addListener((ActionListener) (name, isPressed, tpf) -> {
        Vector2f movement = new Vector2f();
        if(isPressed){
            switch (name) {
                case "LEFT": movement.setX(-1); break;
                case "RIGHT": movement.setX(+1); break;
                case "UP": movement.setY(-1); break;
                case "DOWN": movement.setY(+1); break;
            }
            movement.multLocal(CHARACTER_MASS*MOVE_ACCELERATION);
        }
        entityData.setComponent(character,  new MoveForce(movement));
    }, "LEFT", "RIGHT", "UP", "DOWN");
    getInputManager().addListener((ActionListener) (name, isPressed, tpf) -> {
        if(isPressed) entityData.setComponent(character, new JumpState(true));
    }, "JUMP");
}
 
開發者ID:jvpichowski,項目名稱:ZayES-Bullet,代碼行數:24,代碼來源:CustomCharacterExample.java

示例3: initInputs

import com.jme3.input.controls.ActionListener; //導入依賴的package包/類
private void initInputs() {
    inputManager.addMapping("togglePause", new KeyTrigger(keyInput.KEY_RETURN));
    ActionListener acl = new ActionListener() {
        public void onAction(String name, boolean keyPressed, float tpf) {
            if (name.equals("togglePause") && keyPressed) {
                if (cinematic.getPlayState() == PlayState.Playing) {
                    cinematic.pause();
                } else {
                    cinematic.play();
                }
            }

        }
    };
    inputManager.addListener(acl, "togglePause");
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:17,代碼來源:TestCinematic.java

示例4: initInputs

import com.jme3.input.controls.ActionListener; //導入依賴的package包/類
private void initInputs() {
    inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
 
    ActionListener acl = new ActionListener() {

        public void onAction(String name, boolean keyPressed, float tpf) {
            if (name.equals("toggle") && keyPressed) {
                if(active){
                    active=false;
                    viewPort.removeProcessor(fpp);
                }else{
                    active=true;
                    viewPort.addProcessor(fpp);
                }
            }
        }
    };
         
    inputManager.addListener(acl, "toggle");

}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:22,代碼來源:TestPosterization.java

示例5: invokeActions

import com.jme3.input.controls.ActionListener; //導入依賴的package包/類
private void invokeActions(int hash, boolean pressed) {
    ArrayList<Mapping> maps = bindings.get(hash);
    if (maps == null) {
        return;
    }

    int size = maps.size();
    for (int i = size - 1; i >= 0; i--) {
        Mapping mapping = maps.get(i);
        ArrayList<InputListener> listeners = mapping.listeners;
        int listenerSize = listeners.size();
        for (int j = listenerSize - 1; j >= 0; j--) {
            InputListener listener = listeners.get(j);
            if (listener instanceof ActionListener) {
                ((ActionListener) listener).onAction(mapping.name, pressed, frameTPF);
            }
        }
    }
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:20,代碼來源:InputManager.java

示例6: initControls

import com.jme3.input.controls.ActionListener; //導入依賴的package包/類
public void initControls(InputManager inputManager) {
    inputManager.deleteMapping(SimpleApplication.INPUT_MAPPING_EXIT);

    inputManager.addMapping("open_menu", new KeyTrigger(KeyInput.KEY_ESCAPE));
    inputManager.addMapping("view_atom", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(new ActionListener() {
        @Override
        public void onAction(String name, boolean isPressed, float tpf) {
            if ("open_menu".equals(name) && isPressed) {
                NiftyAppState s = stateManager.getState(NiftyAppState.class);
                if ("menu".equals(s.nifty.getCurrentScreen().getScreenId())) {
                    s.exitMenu();
                } else {
                    s.openMenu();
                }
            } else if ("view_atom".equals(name) && isPressed) {
                triggerViewAtom();
            }
        }
    }, "open_menu", "view_atom");
}
 
開發者ID:matthewseal,項目名稱:MoleculeViewer,代碼行數:22,代碼來源:MVAppState.java

示例7: simpleInitApp

import com.jme3.input.controls.ActionListener; //導入依賴的package包/類
@Override
public void simpleInitApp() {
    emit = new ParticleEmitter("Emitter", Type.Triangle, 300);
    emit.setGravity(0, 0, 0);
    emit.setVelocityVariation(1);
    emit.setLowLife(1);
    emit.setHighLife(1);
    emit.setInitialVelocity(new Vector3f(0, .5f, 0));
    emit.setImagesX(15);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    mat.setTexture("Texture", assetManager.loadTexture("Effects/Smoke/Smoke.png"));
    emit.setMaterial(mat);
    
    rootNode.attachChild(emit);
    
    inputManager.addListener(new ActionListener() {
        
        public void onAction(String name, boolean isPressed, float tpf) {
            if ("setNum".equals(name) && isPressed) {
                emit.setNumParticles(1000);
            }
        }
    }, "setNum");
    
    inputManager.addMapping("setNum", new KeyTrigger(KeyInput.KEY_SPACE));
}
 
開發者ID:chototsu,項目名稱:MikuMikuStudio,代碼行數:27,代碼來源:TestMovingParticle.java

示例8: simpleInitApp

import com.jme3.input.controls.ActionListener; //導入依賴的package包/類
@Override
public void simpleInitApp() {
    EntityId plane = entityData.createEntity();
    entityData.setComponents(plane,
            new Friction(0),
            new RigidBody(false, 0),
            new CustomShape(new PlaneCollisionShape(new Plane(Vector3f.UNIT_Y.clone(), 0))));

    EntityId box = entityData.createEntity();
    entityData.setComponents(box,
            new Friction(0),
            new WarpPosition(new Vector3f(0,1,0), Quaternion.DIRECTION_Z.clone()),
            new RigidBody(false, 10),
            new BoxShape(),
            new WarpVelocity(new Vector3f(1,0,0), new Vector3f()));

    ESBulletState esBulletState = stateManager.getState(ESBulletState.class);
    esBulletState.onInitialize(() -> {
        BulletDebugAppState debugAppState = new BulletDebugAppState(esBulletState.getPhysicsSpace());
        getStateManager().attach(debugAppState);
    });

    getInputManager().addMapping("JUMP", new KeyTrigger(KeyInput.KEY_SPACE));
    getInputManager().addListener((ActionListener) (name, isPressed, tpf) -> {
        if(isPressed){
            entityData.setComponent(box, new Impulse(new Vector3f(0, 20,0), new Vector3f()));
        }
    }, "JUMP");
}
 
開發者ID:jvpichowski,項目名稱:ZayES-Bullet,代碼行數:30,代碼來源:VelocityImpulseTest.java

示例9: setupFlowControls

import com.jme3.input.controls.ActionListener; //導入依賴的package包/類
public void setupFlowControls(ActionListener actionListener) {
    inputManager.deleteMapping(SimpleApplication.INPUT_MAPPING_EXIT);
    inputManager.deleteMapping(SimpleApplication.INPUT_MAPPING_HIDE_STATS);
    inputManager.addMapping(PAUSE, new KeyTrigger(KeyInput.KEY_P));
    inputManager.addMapping(CAMERA, new KeyTrigger(KeyInput.KEY_C));
    inputManager.addMapping(RESET, new KeyTrigger(KeyInput.KEY_R));
    inputManager.addListener(actionListener, PAUSE, CAMERA, RESET);
}
 
開發者ID:ZoltanTheHun,項目名稱:SkyHussars,代碼行數:9,代碼來源:ControlsMapper.java

示例10: createBallShooter

import com.jme3.input.controls.ActionListener; //導入依賴的package包/類
/**
 * creates the necessary inputlistener and action to shoot balls from teh camera
 * @param app
 * @param rootNode
 * @param space
 */
public static void createBallShooter(final Application app, final Node rootNode, final PhysicsSpace space) {
    ActionListener actionListener = new ActionListener() {

        public void onAction(String name, boolean keyPressed, float tpf) {
            Sphere bullet = new Sphere(32, 32, 0.4f, true, false);
            bullet.setTextureMode(TextureMode.Projected);
            Material mat2 = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
            TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
            key2.setGenerateMips(true);
            Texture tex2 = app.getAssetManager().loadTexture(key2);
            mat2.setTexture("ColorMap", tex2);
            if (name.equals("shoot") && !keyPressed) {
                Geometry bulletg = new Geometry("bullet", bullet);
                bulletg.setMaterial(mat2);
                bulletg.setShadowMode(ShadowMode.CastAndReceive);
                bulletg.setLocalTranslation(app.getCamera().getLocation());
                RigidBodyControl bulletControl = new RigidBodyControl(1);
                bulletg.addControl(bulletControl);
                bulletControl.setLinearVelocity(app.getCamera().getDirection().mult(25));
                bulletg.addControl(bulletControl);
                rootNode.attachChild(bulletg);
                space.add(bulletControl);
            }
        }
    };
    app.getInputManager().addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    app.getInputManager().addListener(actionListener, "shoot");
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:35,代碼來源:PhysicsTestHelper.java

示例11: invokeAnalogsAndActions

import com.jme3.input.controls.ActionListener; //導入依賴的package包/類
private void invokeAnalogsAndActions(int hash, float value, boolean applyTpf) {
    if (value < axisDeadZone) {
        invokeAnalogs(hash, value, !applyTpf);
        return;
    }

    ArrayList<Mapping> maps = bindings.get(hash);
    if (maps == null) {
        return;
    }

    boolean valueChanged = !axisValues.containsKey(hash);
    if (applyTpf) {
        value *= frameTPF;
    }

    int size = maps.size();
    for (int i = size - 1; i >= 0; i--) {
        Mapping mapping = maps.get(i);
        ArrayList<InputListener> listeners = mapping.listeners;
        int listenerSize = listeners.size();
        for (int j = listenerSize - 1; j >= 0; j--) {
            InputListener listener = listeners.get(j);

            if (listener instanceof ActionListener && valueChanged) {
                ((ActionListener) listener).onAction(mapping.name, true, frameTPF);
            }

            if (listener instanceof AnalogListener) {
                ((AnalogListener) listener).onAnalog(mapping.name, value, frameTPF);
            }

        }
    }
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:36,代碼來源:InputManager.java

示例12: setupInput

import com.jme3.input.controls.ActionListener; //導入依賴的package包/類
public void setupInput() {
    inputManager.addMapping("start", new KeyTrigger(KeyInput.KEY_PAUSE));
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if(name.equals("start") && isPressed){
                if(cinematic.getPlayState() != PlayState.Playing){
                    cinematic.play();
                }else{
                    cinematic.pause();
                }
            }
        }
    }, "start");
}
 
開發者ID:xbuf,項目名稱:jme3_xbuf,代碼行數:16,代碼來源:TestJaimeJ3o.java

示例13: setupInput

import com.jme3.input.controls.ActionListener; //導入依賴的package包/類
public void setupInput() {
	inputManager.addMapping("start", new KeyTrigger(KeyInput.KEY_PAUSE));
	inputManager.addListener(new ActionListener() {

		public void onAction(String name, boolean isPressed, float tpf) {
			if(name.equals("start") && isPressed){
				if(cinematic.getPlayState() != PlayState.Playing){
					cinematic.play();
				}else{
					cinematic.pause();
				}
			}
		}
	}, "start");
}
 
開發者ID:xbuf,項目名稱:jme3_xbuf,代碼行數:16,代碼來源:TestXbufWithMaterialHook.java

示例14: createBallShooter

import com.jme3.input.controls.ActionListener; //導入依賴的package包/類
/**
 * creates the necessary inputlistener and action to shoot balls from teh camera
 * @param app a
 * @param rootNode r 
 * @param space s
 */
public static void createBallShooter(final Application app, final Node rootNode, final PhysicsSpace space) {
    ActionListener actionListener = new ActionListener() {

        public void onAction(String name, boolean keyPressed, float tpf) {
            Sphere bullet = new Sphere(32, 32, 0.4f, true, false);
            bullet.setTextureMode(TextureMode.Projected);
            Material mat2 = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
            TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
            key2.setGenerateMips(true);
            Texture tex2 = app.getAssetManager().loadTexture(key2);
            mat2.setTexture("ColorMap", tex2);
            if (name.equals("shoot") && !keyPressed) {
                Geometry bulletg = new Geometry("bullet", bullet);
                bulletg.setMaterial(mat2);
                bulletg.setShadowMode(ShadowMode.CastAndReceive);
                bulletg.setLocalTranslation(app.getCamera().getLocation());
                RigidBodyControl bulletControl = new RigidBodyControl(10);
                bulletg.addControl(bulletControl);
                bulletControl.setLinearVelocity(app.getCamera().getDirection().mult(25));
                bulletg.addControl(bulletControl);
                rootNode.attachChild(bulletg);
                space.add(bulletControl);
            }
        }
    };
    app.getInputManager().addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    app.getInputManager().addListener(actionListener, "shoot");
}
 
開發者ID:MyRobotLab,項目名稱:myrobotlab,代碼行數:35,代碼來源:PhysicsTestHelper.java

示例15: simpleInitApp

import com.jme3.input.controls.ActionListener; //導入依賴的package包/類
@Override
public void simpleInitApp() {

    context = this;

    flyCam.setMoveSpeed(50);
    inputManager.addMapping("PRINT",
            new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE));
    inputManager.addListener(new ActionListener() {
        public void onAction(String name, boolean isPressed, float tpf) {
            System.err.println(cam.getRotation());
            System.err.println(cam.getLocation());
        }
    }, "PRINT");
    cam.setLocation(new Vector3f(-14.938178f, 38.859467f, -66.52032f));
    cam.setRotation(new Quaternion(0.32675794f, -6.513824E-4f, 1.0827737E-5f, 0.9451078f));
    initCrossHairs(); // a "+" in the middle of the screen to help aiming

    /**
     * create four colored boxes and a floor to shoot at:
     */
    //rootNode.attachChild(makeFloor());
    SealField sealField = new SealField(assetManager, inputManager, cam, 10);

    sealField.setLocalTranslation(-40, 0, -40);

    rootNode.attachChild(sealField);

    rootNode.attachChild(assetManager.loadModel("Scenes/world.j3o"));

}
 
開發者ID:kemonoske,項目名稱:ArcaneMining,代碼行數:32,代碼來源:Main.java


注:本文中的com.jme3.input.controls.ActionListener類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。