Re: Java programming language and audiogames.
An example, going from memory and not compiling:
import Java.awt.*;
import java.awt.event.*;
import Javax.swing.*;
public class MyGame extends JComponent {
int menuX = 0;
String[] menuText = new String [] {"Play", "Exit"};
public MyGame () {
this.addKeyListener (new KeyAdapter() {
public void keyPressed (KeyEvent ev) {
int k = ev.keyCode;
if (k== KeyEvent.VK_UP) this.menuX--;
else if (k == KeyEvent.VK_DOWN) this.menuX++;
if (this.menuX < 0) this.menuX = this.menuText.length-1;
else if (this.menuX >= this.menuText.length) this.menuX = 0;
// speak, play a sound, whatever, to indicate what you're on. If all else fails, JOptionPane.showInputDialog works, but not very accessibly.
if (k == KeyEvent.VK_SPACE) System.exit(0);
}
});
}
public static void main (String[] args) {
JFrame frame = new JFrame ("test menu");
frame.setVisible(true);
MyGame game = new MyGame();
frame.addComponent (game);
game.setFocusable (true);
game.requestFocus();
}
}
That's probably riddled with errors, but hopefully it gets the idea across.
-- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector