本文整理汇总了Java中com.badlogic.gdx.scenes.scene2d.ui.TextField类的典型用法代码示例。如果您正苦于以下问题:Java TextField类的具体用法?Java TextField怎么用?Java TextField使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TextField类属于com.badlogic.gdx.scenes.scene2d.ui包,在下文中一共展示了TextField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ServerSetupMenu
import com.badlogic.gdx.scenes.scene2d.ui.TextField; //导入依赖的package包/类
public ServerSetupMenu(final Save save) {
super();
title = new Label(Localization.get("menu.server.title"), skin.get("title", Label.LabelStyle.class));
saveLabel = new Label(Localization.get("menu.server.save", save.name), skin);
saveLabel.setAlignment(Align.center);
port = new TextField("", skin);
port.setMessageText(Localization.get("menu.server.port", Settings.getIntegerSettingValue(Settings.NETWORKING_PORT)));
port.setTextFieldFilter(new TextField.TextFieldFilter.DigitsOnlyFilter());
start = new TextButton(Localization.get("menu.server.start"), skin);
back = MenuTools.getBackButton(this);
start.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
int p = port.getText().isEmpty() ? Settings.getIntegerSettingValue(Settings.NETWORKING_PORT) : Integer.parseInt(port.getText());
Adapter.setMenu(new ServerRunningMenu(save, p));
}
});
stage.addActor(title);
stage.addActor(saveLabel);
stage.addActor(port);
stage.addActor(start);
stage.addActor(back);
}
示例2: show
import com.badlogic.gdx.scenes.scene2d.ui.TextField; //导入依赖的package包/类
@Override
public void show() {
player = new Player(Assets.random());
client = new Client(player);
stage = new Stage();
Image logo = new Image(Assets.LOGO);
logo.setPosition((Gdx.graphics.getWidth() - logo.getWidth()) / 2, Gdx.graphics.getHeight() * 0.85f);
Image shadow = dropShadow(logo);
stage.addActor(logo);
stage.addActor(shadow);
stage.addActor(new PlayGroup(client));
stage.getRoot().addCaptureListener(new InputListener() {
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
if (!(event.getTarget() instanceof TextField)) stage.setKeyboardFocus(null);
return true;
}
});
Gdx.input.setInputProcessor(stage);
}
示例3: MultiplayerConnectMenu
import com.badlogic.gdx.scenes.scene2d.ui.TextField; //导入依赖的package包/类
public MultiplayerConnectMenu() {
super();
title = new Label(Localization.get("menu.multiplayer.title"), skin.get("title", Label.LabelStyle.class));
address = new TextField("", skin);
address.setMessageText(Localization.get("menu.multiplayer.address"));
port = new TextField("", skin);
port.setMessageText(Localization.get("menu.multiplayer.port", 24842)); //Not "Settings.getIntegerSettingValue(Settings.NETWORKING_PORT)" because the port is set on the server
port.setTextFieldFilter(new TextField.TextFieldFilter.DigitsOnlyFilter());
connect = new TextButton(Localization.get("menu.multiplayer.connect"), skin);
back = MenuTools.getBackButton(this);
connect.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
Adapter.setMenu(new MultiplayerLoadingMenu(address.getText().isEmpty() ? "localhost" : address.getText(), port.getText().isEmpty() ? 24842 : Integer.parseInt(port.getText())));
}
});
stage.addActor(title);
stage.addActor(address);
stage.addActor(port);
stage.addActor(connect);
stage.addActor(back);
}
示例4: getTextField
import com.badlogic.gdx.scenes.scene2d.ui.TextField; //导入依赖的package包/类
private TextField getTextField(VisualSettingManager visualSettingManager) {
final TextField textField = new TextField(i + "", visualSettingManager.getSkin());
textField.addListener(new EventListener() {
@Override
public boolean handle(Event event) {
if (!(event instanceof SettingsMenu.SaveEvent)) return false;
try {
int n = Integer.parseInt(textField.getText());
if (hasRange && (n < rangeStart || n > rangeEnd)) {
throw new NumberFormatException();
} else {
set(n);
return true;
}
} catch (Exception e) {
textField.setText(i + "");
return false;
}
}
});
textField.setTextFieldFilter(new TextField.TextFieldFilter.DigitsOnlyFilter());
if (hasRange) textField.setMessageText("(" + rangeStart + "-" + rangeEnd + ")");
return textField;
}
示例5: AskForIpDialog
import com.badlogic.gdx.scenes.scene2d.ui.TextField; //导入依赖的package包/类
public AskForIpDialog(SettingsChoosingState state, ConnectionInfo defaultConnection)
{
super("Connect to server", Settings.DEFAULT_SKIN);
this.linkedState = state;
ipField = new TextField(defaultConnection.getIp(), getSkin());
text("Server ip: ");
this.getContentTable().add(ipField);
this.getContentTable().row();
text("Tcp port: ");
tcpPortField = new IntegerField(defaultConnection.getTcpPort(), getSkin(), MAX_PORT_DIGITS);
this.getContentTable().add(tcpPortField);
this.getContentTable().row();
text("Udp port: ");
udpPortField = new IntegerField(defaultConnection.getUdpPort(), getSkin(), MAX_PORT_DIGITS);
this.getContentTable().add(udpPortField);
this.getContentTable().row();
this.button("Ok", DialogResults.OK);
button("Cancel", DialogResults.CANCEL);
}
示例6: createButton
import com.badlogic.gdx.scenes.scene2d.ui.TextField; //导入依赖的package包/类
private void createButton() {
Skin skin = getGameObject().getComponentInParent(JCanvas.class).getSkin();
// TextFieldStyle style = new TextFieldStyle(skin.get("default", TextFieldStyle.class));
int realSize = (int) (((getTransform().getScale().x + getTransform().getScale().y) / 2) * fontSize);
SmartFontGenerator fontGen = new SmartFontGenerator();
FileHandle exoFile = Gdx.files.internal(fontResource.getResourcePath());
BitmapFont fontBitmap = fontGen.createFont(exoFile, fontResource.getResourcePath() + realSize, realSize);
TextFieldStyle styleDefault = skin.get("default", TextFieldStyle.class);
TextFieldStyle style = new TextFieldStyle(fontBitmap, fontColor, styleDefault.cursor, styleDefault.selection, styleDefault.background);
style.fontColor = fontColor;
textField = new TextField(text, style);
textField.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
text = textField.getText();
}
});
}
示例7: SettingScreenOld
import com.badlogic.gdx.scenes.scene2d.ui.TextField; //导入依赖的package包/类
public SettingScreenOld(Viewport viewport, Skin skin) {
float screenWidth = Gdx.graphics.getWidth();
float screenHeight = Gdx.graphics.getHeight();
stage = new Stage(viewport);
Label label = new Label("Player 1", skin);
label.setPosition(screenWidth / 2, screenHeight - 10, Align.top);
stage.addActor(label);
label = new Label("Forward", skin);
label.setPosition(10, screenHeight - 60);
stage.addActor(label);
TextField field = new TextField("", skin);
field.setPosition(50, screenHeight - 20);
field.setWidth(100);
field.setHeight(50);
stage.addActor(field);
}
示例8: shouldParseTextField
import com.badlogic.gdx.scenes.scene2d.ui.TextField; //导入依赖的package包/类
@Test
@NeedGL
public void shouldParseTextField() throws Exception {
FileHandle defaultFont = Gdx.files.internal("share/MLFZS.ttf");
CocoStudioUIEditor editor = new CocoStudioUIEditor(
Gdx.files.internal("textField/MainScene.json"), null, null, defaultFont, null);
Group group = editor.createGroup();
TextField textField = group.findActor("TextField_1");
assertThat(textField.getText(), is("Here is text"));
assertThat(textField.getMessageText(), is("Place Holder"));
assertThat(textField.getText(), is("Here is text"));
assertThat(textField.getColor().toString(), is("008000ff"));
assertThat(textField.getListeners().size, is(1));
textField = group.findActor("TextField_2");
assertThat(textField.getText(), is(""));
assertThat(textField.getMessageText(), is("Place Holder"));
assertThat(textField.getColor().toString(), is("ff0000ff"));
assertThat(textField.getListeners().size, is(1));
}
示例9: addEntry
import com.badlogic.gdx.scenes.scene2d.ui.TextField; //导入依赖的package包/类
public void addEntry(final String name, int width) {
final TextField textField = new TextField("", getSkin());
nameToTextField.put(name, textField);
add(new Label(name, getSkin())).fill().left();
if (width != -1) {
add(textField).fill().right().width(width);
} else {
add(textField).fill().right();
}
textField.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
if (listener != null) {
listener.onChange(name, textField.getText());
}
}
});
row();
pack();
}
示例10: SaveAsDialog
import com.badlogic.gdx.scenes.scene2d.ui.TextField; //导入依赖的package包/类
public SaveAsDialog(Skin skin) {
super("save as..", skin);
getContentTable().pad(15);
Label nameLabel = new Label("Name:", skin);
getContentTable().add(nameLabel);
final TextField textField = new TextField("", skin);
textField.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
resultValue = textField.getText();
}
});
getContentTable().add(textField);
button("save", true);
button("cancel", false);
pack();
}
示例11: ConsoleView
import com.badlogic.gdx.scenes.scene2d.ui.TextField; //导入依赖的package包/类
public ConsoleView(Skin skin) {
this.skin = skin;
entriesStack = new Table(skin);
entriesStack.setFillParent(true);
scrollPane = new ScrollPane(entriesStack, skin);
scrollPane.setFadeScrollBars(false);
scrollPane.setScrollbarsOnTop(false);
scrollPane.setOverscroll(false, false);
inputField = new TextField("", skin);
this.add(scrollPane).expand().fill().pad(2).row();
this.add(inputField).expandX().fillX().pad(4);
setTouchable(Touchable.enabled);
clearEntries();
}
示例12: createStaticMenu
import com.badlogic.gdx.scenes.scene2d.ui.TextField; //导入依赖的package包/类
private void createStaticMenu() {
Table container = new Table();
container.setFillParent(true);
container.top();
stage.addActor(container);
Label title = new Label("Game Over", uiSkin, "title");
Label scoreLabel = new Label ("Score : "+ remoteScore.getScore(), uiSkin);
usernameField = new TextField("", uiSkin);
submitButton = new TextButton("Envoyer", uiSkin);
submitButton.addListener(new SubmitScoreListener(usernameField, remoteScore, stage));
TextButton menuButton = new TextButton("Quitter", uiSkin);
menuButton.addListener(new ButtonRedirectListener(game, new MainMenuScreen(game)));
Table actorContainer = new Table();
actorContainer.add(scoreLabel).padBottom(10).colspan(2);
actorContainer.row();
actorContainer.add(usernameField).padRight(10);
actorContainer.add(submitButton);
container.add(title).padTop(10);
container.row();
container.add(actorContainer).expand();
container.row();
container.add(menuButton).bottom().left().pad(10);
}
示例13: processForActor
import com.badlogic.gdx.scenes.scene2d.ui.TextField; //导入依赖的package包/类
@Override
protected void processForActor(final LmlParser parser, final LmlTag tag, final Actor actor,
final String rawAttributeData) {
// Applied if not in a cell.
if (actor instanceof Label) {
((Label) actor).setAlignment(LmlUtilities.parseAlignment(parser, actor, rawAttributeData));
} else if (actor instanceof Table) {
((Table) actor).align(LmlUtilities.parseAlignment(parser, actor, rawAttributeData));
} else if (actor instanceof Image) {
((Image) actor).setAlign(LmlUtilities.parseAlignment(parser, actor, rawAttributeData));
} else if (actor instanceof HorizontalGroup) {
((HorizontalGroup) actor).align(LmlUtilities.parseAlignment(parser, actor, rawAttributeData));
} else if (actor instanceof VerticalGroup) {
((VerticalGroup) actor).align(LmlUtilities.parseAlignment(parser, actor, rawAttributeData));
} else if (actor instanceof TextField) {
((TextField) actor).setAlignment(LmlUtilities.parseAlignment(parser, actor, rawAttributeData));
} else {
// Exception:
super.processForActor(parser, tag, actor, rawAttributeData);
}
}
示例14: process
import com.badlogic.gdx.scenes.scene2d.ui.TextField; //导入依赖的package包/类
@Override
public void process(final LmlParser parser, final LmlTag tag, final TextField actor,
final String rawAttributeData) {
@SuppressWarnings("unchecked") final ActorConsumer<Boolean, Character> filter = (ActorConsumer<Boolean, Character>) parser
.parseAction(rawAttributeData, Character.valueOf(' '));
if (filter == null) {
parser.throwErrorIfStrict(
"Text field filter attribute requires ID of an action that consumes a Character and returns a boolean or Boolean. Valid action not found for name: "
+ rawAttributeData);
return;
}
actor.setTextFieldFilter(new TextFieldFilter() {
@Override
public boolean acceptChar(final TextField textField, final char character) {
return filter.consume(character);
}
});
}
示例15: process
import com.badlogic.gdx.scenes.scene2d.ui.TextField; //导入依赖的package包/类
@Override
public void process(final LmlParser parser, final LmlTag tag, final TextField actor,
final String rawAttributeData) {
final ActorConsumer<?, Character> listener = parser.parseAction(rawAttributeData, Character.valueOf(' '));
if (listener == null) {
parser.throwErrorIfStrict(
"Text field listener attribute requires ID of an action that consumes a Character. Valid action not found for name: "
+ rawAttributeData);
return;
}
actor.setTextFieldListener(new TextFieldListener() {
@Override
public void keyTyped(final TextField textField, final char character) {
listener.consume(character);
}
});
}