Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package test;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
public class BarebonesStage extends ApplicationAdapter {
Stage stage;
public void create () {
stage = new Stage(new ScreenViewport());
Gdx.input.setInputProcessor(stage);
Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
Preferences prefs = Gdx.app.getPreferences("preferences");
final TextField tf = new TextField(prefs.getString("textField", "Enter text..."), skin);
final Button b = new TextButton("Click Me", skin);
b.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
Preferences prefs = Gdx.app.getPreferences("preferences");
prefs.putString("textField", tf.getText());
prefs.flush();
}
});
Table table = new Table();
table.setFillParent(true);
table.add(tf);
table.add(b);
stage.addActor(table);
}
public void render () {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.draw();
}
public void resize (int width, int height) {
// Pass false to not modify the camera position.
stage.getViewport().update(width, height, true);
}
public static void main (String[] args) throws Exception {
new LwjglApplication(new BarebonesStage());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.