Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package strongdk.examples;
- import com.jme3.app.SimpleApplication;
- import com.jme3.font.BitmapFont;
- import com.jme3.math.ColorRGBA;
- import com.jme3.system.AppSettings;
- import strongdk.jme.gui.GuiElement;
- import strongdk.jme.gui.GuiElement.GuiElementAdapter;
- /**
- *
- * @author Daniel Strong aka icamefromspace
- */
- public class TestGuiElement extends SimpleApplication {
- public static void main(String[] args) {
- TestGuiElement app = new TestGuiElement();
- AppSettings settings = new AppSettings(true);
- settings.setWidth(800);
- settings.setHeight(600);
- app.setSettings(settings);
- app.setShowSettings(false);
- app.start();
- }
- private GuiElement textElement, labelElement, redElement, blueElement, toggleElement;
- @Override
- public void simpleInitApp() {
- setDisplayFps(false);
- setDisplayStatView(false);
- flyCam.setEnabled(false);
- getViewPort().setBackgroundColor(new ColorRGBA(100 / 255f, 149 / 255f, 237 / 255f, 1f));
- textElement = GuiElement.makeTextField(guiViewPort, inputManager, assetManager, "You can edit this element.", 400, 75);
- textElement.setDimensions(210, 43.75f);
- textElement.setTextAlignment(BitmapFont.Align.Center);
- textElement.center(0, 225);
- textElement.setListener(new GuiElementAdapter() {
- @Override
- public void onTextInput(GuiElement element) {
- System.out.println("text entered: " + textElement.getText());
- }
- });
- labelElement = GuiElement.makeLabel(getGuiViewPort(), inputManager, assetManager, "This example shows different ways to use the GuiElement.", 500, 100);
- labelElement.center(0, 100);
- redElement = GuiElement.makeButton(getGuiViewPort(), inputManager, assetManager, "Red", 200, 100);
- redElement.center(-110, -50);
- redElement.setListener(new GuiElementAdapter() {
- @Override
- public void onPressed(GuiElement element) {
- getViewPort().setBackgroundColor(ColorRGBA.Red);
- }
- });
- blueElement = GuiElement.makeButton(getGuiViewPort(), inputManager, assetManager, "Blue", 200, 100);
- blueElement.center(110, -50);
- blueElement.setListener(new GuiElementAdapter() {
- @Override
- public void onPressed(GuiElement element) {
- getViewPort().setBackgroundColor(ColorRGBA.Blue);
- }
- });
- toggleElement = GuiElement.makeToggleButton(getGuiViewPort(), inputManager, assetManager, "Disable Buttons", 200, 100);
- toggleElement.center(0, -200);
- toggleElement.setToggled(true);
- toggleElement.setListener(new GuiElementAdapter() {
- @Override
- public void onPressed(GuiElement element) {
- textElement.setEnabled(!textElement.isEnabled());
- redElement.setEnabled(!redElement.isEnabled());
- blueElement.setEnabled(!blueElement.isEnabled());
- if (redElement.isEnabled()) {
- toggleElement.setText("Disable Buttons");
- } else {
- toggleElement.setText("Enable Buttons");
- }
- }
- });
- guiNode.attachChild(textElement);
- guiNode.attachChild(labelElement);
- guiNode.attachChild(redElement);
- guiNode.attachChild(blueElement);
- guiNode.attachChild(toggleElement);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement