Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package gui;
- import org.newdawn.slick.Color;
- import org.newdawn.slick.GameContainer;
- import org.newdawn.slick.Graphics;
- import java.awt.event.KeyEvent;
- import java.awt.event.KeyListener;
- /**
- * User: Zsolt
- * Date: 2013.04.21.
- * Time: 17:52
- */
- public class TextField extends GUI implements KeyListener {
- private boolean focused = false;
- private String text = "";
- public TextField(int x, int y, int width, int height) {
- super(x, y, width, height);
- }
- public boolean isFocused() {
- return focused;
- }
- public void setFocused(boolean focused) {
- this.focused = focused;
- }
- public void append(String text) {
- this.text = this.text + text;
- }
- public void remove() {
- if (text.length() > 0) {
- text = text.substring(0, text.length() - 1);
- }
- }
- @Override
- public void render(GameContainer gc, Graphics g) {
- if (!focused) {
- g.setColor(Color.gray);
- } else {
- g.setColor(Color.orange);
- }
- g.fillRect(x - width / 2, y - height / 2, width, height);
- g.setColor(Color.darkGray);
- g.fillRect(x - width / 2 + 5, y - height / 2 + 5, width - 10, height - 10);
- g.setColor(Color.white);
- g.drawString(text, x - g.getFont().getWidth(text) / 2, y - g.getFont().getHeight(text) / 2);
- }
- @Override
- public void keyTyped(KeyEvent e) {
- }
- @Override
- public void keyPressed(KeyEvent e) {
- System.out.println("asd");
- }
- @Override
- public void keyReleased(KeyEvent e) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement