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


Java Button類代碼示例

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


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

示例1: createSkins

import com.badlogic.gdx.scenes.scene2d.ui.Button; //導入依賴的package包/類
/**
 * Function used to create the Skins' Buttons and Labels and associate them to a given table, organized.
 * It also adds Listeners to the Skins' Buttons.
 *
 * @param table Table where the Skins' Labels and Buttons will be organized.
 */
private void createSkins(Table table) {
    for (int i = 0; i < game.getNumSkins(); ++i) {

        //Adding Buttons and Labels to the Arrays
        skinButtons.add(new Button(new TextureRegionDrawable(new TextureRegion(game.getAssetManager().get("big_skins/skin" + (i < 10 ? "0" : "") + i + ".png", Texture.class)))));
        skinLabels.add(new Label("Current", skin1));

        final int j = i; //Needed for Listener initialization
        skinButtons.get(i).addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                setCurrentLabel(j);
            }
        });

        table.add(skinButtons.get(i)).size(BUTTON_SIZE, BUTTON_SIZE).pad(IMAGE_EDGE);
    }
    table.row();

    for (int i = 0; i < game.getNumSkins(); ++i)
        table.add(skinLabels.get(i));

    initializeCurrentSkin();
}
 
開發者ID:AndreFCruz,項目名稱:feup-lpoo-armadillo,代碼行數:31,代碼來源:CustomizeMenuScreen.java

示例2: initHUD

import com.badlogic.gdx.scenes.scene2d.ui.Button; //導入依賴的package包/類
/**
 * Function used to initialize all the elements of the HUD and add the respective Listeners.
 */
private void initHUD() {
    Table hudTable = new Table();
    hudTable.setFillParent(true);

    Button pauseButton = new Button(new TextureRegionDrawable(
            new TextureRegion(game.getAssetManager().get("pause.png", Texture.class))));

    scoreText = new Label("0:00", skin);
    scoreText.setFontScale(FONT_SCALE, FONT_SCALE);

    pauseButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            model.togglePause();
        }
    });

    hudTable.top();
    hudTable.add(scoreText).size(HUD_ELEMENTS_SIZE, HUD_ELEMENTS_SIZE).expandX()
            .left().fill().padLeft(HORIZONTAL_PAD).padTop(VERTICAL_PAD);
    hudTable.add(pauseButton).size(HUD_ELEMENTS_SIZE, HUD_ELEMENTS_SIZE).fill()
            .padRight(HORIZONTAL_PAD).padTop(VERTICAL_PAD);

    this.addActor(hudTable);
}
 
開發者ID:AndreFCruz,項目名稱:feup-lpoo-armadillo,代碼行數:29,代碼來源:HudMenu.java

示例3: StageControl

import com.badlogic.gdx.scenes.scene2d.ui.Button; //導入依賴的package包/類
public StageControl() {
	// Config
	config = new ConfigGeneral();
	config.load();
	// Spritebatch
	spritebatch = new SpriteBatch();
	// Screen touchable
	wiiScreen = new Button(new Button.ButtonStyle());
	wiiScreen.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
	wiiImage = new Texture("image/placeholder.png");
	addActor(wiiScreen);
	// Initialize controls
	for (Control control : controls)
		control.init(this);
	// Audio
	audioThread = new AudioThread();
	audioThread.start();
	// Video
	videoThread = new VideoThread();
	videoThread.start();
	// Command
	commandThread = new CommandThread();
	commandThread.start();
}
 
開發者ID:rolandoislas,項目名稱:drc-sim-client,代碼行數:25,代碼來源:StageControl.java

示例4: create

import com.badlogic.gdx.scenes.scene2d.ui.Button; //導入依賴的package包/類
public void create() {
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    //font = new BitmapFont();
    //skin = new Skin();
    //buttonAtlas = new TextureAtlas(Gdx.files.internal());
    //skin.addRegions(buttonAtlas);

    button = new Button();
    button.setStyle(new Button.ButtonStyle());

    button.addCaptureListener(new EventListener() {
        @Override
        public boolean handle(Event event) {
            Gdx.app.log("LOG", "event " + event);
            return false;
        }
    });
    stage.addActor(button);
}
 
開發者ID:MissionBit,項目名稱:summer17-android,代碼行數:21,代碼來源:MenuState.java

示例5: drawdefenders

import com.badlogic.gdx.scenes.scene2d.ui.Button; //導入依賴的package包/類
private void drawdefenders(){
    defenders = new DrawDefenders();
    groupBtnDefender = new Group();
    Button btn1 = new Button(new ImageButton.ImageButtonStyle());
    btn1.setName("btn1");
    btn1.setSize(Gdx.graphics.getWidth() * 0.18f, Gdx.graphics.getWidth() * 0.2f);
    btn1.setPosition(Gdx.graphics.getWidth() * 0.025f, Gdx.graphics.getHeight() / 2.3f - Gdx.graphics.getHeight() * 0.14f);
    groupBtnDefender.addActor(btn1);
    Button btn2 = new Button(new ImageButton.ImageButtonStyle());
    btn2.setName("btn2");
    btn2.setSize(Gdx.graphics.getWidth() * 0.18f, Gdx.graphics.getWidth() * 0.2f);
    btn2.setPosition(Gdx.graphics.getWidth() * 0.025f, Gdx.graphics.getHeight() / 2.3f);
    groupBtnDefender.addActor(btn2);
    Button btn3 = new Button(new ImageButton.ImageButtonStyle());
    btn3.setName("btn3");
    btn3.setSize(Gdx.graphics.getWidth() * 0.18f, Gdx.graphics.getWidth() * 0.2f);
    btn3.setPosition(Gdx.graphics.getWidth() * 0.025f, Gdx.graphics.getHeight() / 2.3f + Gdx.graphics.getHeight() * 0.14f);
    groupBtnDefender.addActor(btn3);
}
 
開發者ID:TudorRosca,項目名稱:enklave,代碼行數:20,代碼來源:ScreenCombat.java

示例6: drawAttachers

import com.badlogic.gdx.scenes.scene2d.ui.Button; //導入依賴的package包/類
private void drawAttachers(){
    attachers = new DrawAttachers();
    Button btn1 = new Button(new ImageButton.ImageButtonStyle());
    btn1.setName("btn4");
    btn1.setSize(Gdx.graphics.getWidth() * 0.18f, Gdx.graphics.getWidth() * 0.2f);
    btn1.setPosition(Gdx.graphics.getWidth() - btn1.getWidth() * 1.13f, Gdx.graphics.getHeight() / 2.3f - Gdx.graphics.getHeight() * 0.14f);
    groupBtnDefender.addActor(btn1);
    Button btn2 = new Button(new ImageButton.ImageButtonStyle());
    btn2.setName("btn5");
    btn2.setSize(Gdx.graphics.getWidth() * 0.18f, Gdx.graphics.getWidth() * 0.2f);
    btn2.setPosition(Gdx.graphics.getWidth() - btn2.getWidth() * 1.13f, Gdx.graphics.getHeight() / 2.3f);
    groupBtnDefender.addActor(btn2);
    Button btn3 = new Button(new ImageButton.ImageButtonStyle());
    btn3.setName("btn6");
    btn3.setSize(Gdx.graphics.getWidth() * 0.18f, Gdx.graphics.getWidth() * 0.2f);
    btn3.setPosition(Gdx.graphics.getWidth() - btn3.getWidth() * 1.13f, Gdx.graphics.getHeight() / 2.3f + Gdx.graphics.getHeight() * 0.14f);
    groupBtnDefender.addActor(btn3);
}
 
開發者ID:TudorRosca,項目名稱:enklave,代碼行數:19,代碼來源:ScreenCombat.java

示例7: QuestRewardDialog

import com.badlogic.gdx.scenes.scene2d.ui.Button; //導入依賴的package包/類
public QuestRewardDialog(ActorManipulator linkedManipulator, long id, QuestFinishedRewardPacket questReward,
        ItemPositionSupplier desiredItemPositionSupplier, PacketsSender packetsSender)
{
    super(questReward.getQuestName(), linkedManipulator, id);

    for (ItemRewardPacket itemReward : questReward.getItemReward())
    {
        ButtonField<QuestRewardIcon> rewardField = createRewardField(desiredItemPositionSupplier, packetsSender,
                questReward.getQuestName());
        QuestRewardIcon questRewardIcon = new QuestRewardIcon(itemReward.getItemIdentifier(),
                itemReward.getNumberOfItems());
        rewardField.put(questRewardIcon);
        rewardFields.put(itemReward.getItemIdentifier(), rewardField);
        this.add(rewardField);
    }
    this.row();
    goldLabel = new StringValueLabel<>("Gold: ", Settings.DEFAULT_SKIN,
            questReward.getGoldReward());
    Button takeGoldButton = ButtonCreator.createTextButton("Take",
            () -> packetsSender.send(PacketsMaker.makeRetrieveGoldRewardPacket(questReward.getQuestName())));
    this.add(goldLabel);
    this.add(takeGoldButton);
    this.pack();
}
 
開發者ID:MMORPG-Prototype,項目名稱:MMORPG_Prototype,代碼行數:25,代碼來源:QuestRewardDialog.java

示例8: ContainerDialog

import com.badlogic.gdx.scenes.scene2d.ui.Button; //導入依賴的package包/類
public ContainerDialog(CharacterItemDataPacket[] itemsToShow, int gold, String title,
		ActorManipulator linkedContainer, PacketsSender packetsSender, long containerId,
		ItemPositionSupplier userInventoryTakeItemPositionSupplier)
{
	super(title, linkedContainer, containerId);

	int numberOfItems = itemsToShow.length;

	addFieldRow(itemsToShow, packetsSender, numberOfItems, 0, userInventoryTakeItemPositionSupplier);
	for (int i = ROW_LENGTH; i < numberOfItems; i += ROW_LENGTH)
	{
		this.row();
		addFieldRow(itemsToShow, packetsSender, numberOfItems, i, userInventoryTakeItemPositionSupplier);
	}
	this.row();

	goldLabel = new StringValueLabel<>("Gold: ", Settings.DEFAULT_SKIN, gold);
	this.getButtonTable().add(goldLabel).align(Align.right);
	Button takeGoldButton = ButtonCreator.createTextButton("Take",
			() -> packetsSender.send(PacketsMaker.makeTakingGoldFromContainerPacket(containerId)));

	this.getButtonTable().add(takeGoldButton).align(Align.bottomRight);
	setWidth(ROW_LENGTH * BUTTON_SIZE + 50);
	setHeight(120);
}
 
開發者ID:MMORPG-Prototype,項目名稱:MMORPG_Prototype,代碼行數:26,代碼來源:ContainerDialog.java

示例9: ShopBuyingDialog

import com.badlogic.gdx.scenes.scene2d.ui.Button; //導入依賴的package包/類
public ShopBuyingDialog(ShopItem item, UserInterface linkedInterface, PacketsSender packetsSender, long shopId)
{
	super(DialogUtils.humanReadableFromItemIdentifier(item.getItem().getIdentifier()), linkedInterface.getDialogs(),
			item.getItem().getId());
	this.item = item;
	totalPrice = new StringValueLabel<>("Total: ", getSkin(), item.getPrice());
	Texture texture = item.getItem().getTexture();
	Image image = new Image(texture);
	Table upperContainer = new Table();
	upperContainer.add(image).width(32).height(32).padRight(43);
	upperContainer.add(numberOfItemsField).width(40).align(Align.right);
	this.getContentTable().add(upperContainer).align(Align.left);
	this.getContentTable().row();
	this.getContentTable().add(totalPrice);
	this.getContentTable().row();
	Button buyButton = ButtonCreator.createTextButton("Buy", () -> tryToBuyAction(packetsSender, shopId, linkedInterface));
	this.getContentTable().add(buyButton);
	pack();
	DialogUtils.centerPosition(this);
}
 
開發者ID:MMORPG-Prototype,項目名稱:MMORPG_Prototype,代碼行數:21,代碼來源:ShopBuyingDialog.java

示例10: MenuDialog

import com.badlogic.gdx.scenes.scene2d.ui.Button; //導入依賴的package包/類
public MenuDialog(UserInterface linkedInterface)
{
	super("Menu", Settings.DEFAULT_SKIN);

	Button closeButton = new CloseButton(this);
	getTitleTable().add(closeButton).size(15, 15).padRight(-5).top().right();

	TextButton characterChangeButton = ButtonCreator.createTextButton("Change character",
			() -> linkedInterface.userWantsToChangeCharacter());
	TextButton logOutButton = ButtonCreator.createTextButton("Log out", () -> linkedInterface.userWantsToLogOut());
	TextButton disconnectButton = ButtonCreator.createTextButton("Disconnect", () -> linkedInterface.userWantsToDisconnect());
	TextButton exitButton = ButtonCreator.createTextButton("Exit", () -> Gdx.app.exit());

	getContentTable().add(characterChangeButton);
	getContentTable().row();
	getContentTable().add(logOutButton);
	getContentTable().row();
	getContentTable().add(disconnectButton);
	getContentTable().row();
	getContentTable().add(exitButton);
	getContentTable().row();

	DialogUtils.centerPosition(this);
	pack();
}
 
開發者ID:MMORPG-Prototype,項目名稱:MMORPG_Prototype,代碼行數:26,代碼來源:MenuDialog.java

示例11: GameButton

import com.badlogic.gdx.scenes.scene2d.ui.Button; //導入依賴的package包/類
public GameButton(float WIDTH, float HEIGHT, String drawable, boolean isCheckable) {
    audioManager = AudioManager.getInstance();
    skin = new Skin();
    skin.addRegions(AssetsManager.getTextureAtlas());

    Button.ButtonStyle buttonStyle = new Button.ButtonStyle();
    buttonStyle.up = skin.getDrawable(drawable);
    buttonStyle.down = skin.getDrawable(drawable + "_pressed");
    if (isCheckable) {
        buttonStyle.checked = skin.getDrawable(drawable + "_pressed");
    }
    setStyle(buttonStyle);
    setSize(WIDTH, HEIGHT);

    rectangle = new Rectangle(getX(),getY(),getWidth(),getHeight());
    addListener(new ClickListener(){
        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            audioManager.playSound(audioManager.getButtonSound());
        }
    });
}
 
開發者ID:ZephyrVentum,項目名稱:FlappySpinner,代碼行數:24,代碼來源:GameButton.java

示例12: initPlayerButton

import com.badlogic.gdx.scenes.scene2d.ui.Button; //導入依賴的package包/類
private void initPlayerButton() {
    playerButton = new Button(new Button.ButtonStyle());
    playerButton.setWidth(460);
    playerButton.setHeight(360);
    playerButton.setX(10);
    playerButton.setY(170);
    playerButton.setDebug(true);

    stage.addActor(playerButton);

    playerButton.addListener(new ClickListener() {
        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            player.reactOnClick();
            game.addPoint();
            return super.touchDown(event, x, y, pointer, button);
        }
    });
}
 
開發者ID:BePeGames,項目名稱:ClickerGame,代碼行數:20,代碼來源:GamePlayScreen.java

示例13: initResetButton

import com.badlogic.gdx.scenes.scene2d.ui.Button; //導入依賴的package包/類
private void initResetButton() {
    resetButton = new Button(new Button.ButtonStyle());
    resetButton.setWidth(40);
    resetButton.setHeight(20);
    resetButton.setX(160);
    resetButton.setY(550);
    resetButton.setDebug(true);

    stage.addActor(resetButton);

    resetButton.addListener(new ClickListener() {
        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            game.resetPoints();
            return super.touchDown(event, x, y, pointer, button);
        }
    });
}
 
開發者ID:BePeGames,項目名稱:ClickerGame,代碼行數:19,代碼來源:GamePlayScreen.java

示例14: createMobileMoveButton

import com.badlogic.gdx.scenes.scene2d.ui.Button; //導入依賴的package包/類
private void createMobileMoveButton() {
    float screenWidth = Gdx.graphics.getWidth();
    float screenHeight = Gdx.graphics.getHeight();

    moveButton = new Button(skin);
    moveButton.getStyle().down = new TextureRegionDrawable(AssetManager.getInstance().getTextureRegion("default")).tint(MOBILE_BUTTON_DOWN_COLOR);
    moveButton.getStyle().up = new TextureRegionDrawable(AssetManager.getInstance().getTextureRegion("default")).tint(MOBILE_BUTTON_UP_COLOR);
    moveButton.setSize(screenWidth * 0.35f, screenHeight * 0.2f);
    moveButton.setPosition(screenWidth / 32, screenHeight / 32f);
    moveButton.addListener(new com.badlogic.gdx.scenes.scene2d.InputListener() {
        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            boolean isTutorial = DAO.getInstance().getBoolean(DAO.IS_NEW_KEY, true);
            if (Globals.getGameState() == Game.State.WAIT_FOR_INPUT) {
                Globals.setGameState(Game.State.RUNNING);
            }

            if (Globals.getGameState() == Game.State.RUNNING) {
                movePointer = pointer;
            }
            return true;
        }
    });

    stage.addActor(moveButton);
}
 
開發者ID:alexschimpf,項目名稱:joe,代碼行數:27,代碼來源:HUD.java

示例15: getSettingsButton

import com.badlogic.gdx.scenes.scene2d.ui.Button; //導入依賴的package包/類
protected Button getSettingsButton(boolean useText)
{
    Button button = useText
        ? new BeepingImageTextButton("Settings", UIManager.skin, "settings")
        : new BeepingImageButton(UIManager.skin, "settings");

    button.addListener(
        new ClickListener()
        {
            @Override
            public void clicked(InputEvent event, float x, float y)
            {
                ScreenManager.addScreen(new SettingsScreen());
            }
        });

    return button;
}
 
開發者ID:overengineering,項目名稱:space-travels-3,代碼行數:19,代碼來源:Screen.java


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