Browse Source

Added input storage to ui

remotes/origin/menu
fdai7012 11 months ago
committed by Julian
parent
commit
aae0e78bac
  1. 29
      src/main/java/pacmanGame/MyKeyListener.java
  2. 21
      src/main/java/pacmanGame/Program.java

29
src/main/java/pacmanGame/MyKeyListener.java

@ -0,0 +1,29 @@
package pacmanGame;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.ArrayList;
import javax.swing.JFrame;
public class MyKeyListener implements KeyListener {
public ArrayList<Character> inputList = new ArrayList<>();
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyPressed(KeyEvent e) {
inputList.add(e.getKeyChar());
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
}

21
src/main/java/pacmanGame/Program.java

@ -1,19 +1,29 @@
package pacmanGame; package pacmanGame;
import java.awt.*; import java.awt.*;
import javax.swing.*; import javax.swing.*;
public class Program { public class Program {
public static JTextArea textArea;
public MyKeyListener input;
public JTextArea textArea;
public JFrame frame;
public static void main(String[] args) { public static void main(String[] args) {
createAndShowGUI();
Program instance = new Program();
instance.StartGame();
}
public void StartGame() {
CreateAndShowGUI();
} }
private static void createAndShowGUI() {
JFrame frame = new JFrame("PacmaaaAAAYYYHAAAaaam");
public void CreateAndShowGUI() {
frame = new JFrame("PacmaaaAAAYYYHAAAaaam");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 665); frame.setSize(500, 665);
@ -30,5 +40,8 @@ public class Program {
frame.add(textArea, BorderLayout.CENTER); frame.add(textArea, BorderLayout.CENTER);
frame.setLocationRelativeTo(null); frame.setLocationRelativeTo(null);
frame.setVisible(true); frame.setVisible(true);
input = new MyKeyListener();
frame.addKeyListener(input);
} }
} }
Loading…
Cancel
Save