Trying to create menu bar.
This commit is contained in:
parent
3174669ec3
commit
e19278dfec
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,5 @@
|
|||||||
# Ignore binary files
|
# Ignore binary files
|
||||||
bin/*
|
bin/*
|
||||||
|
|
||||||
|
# Just in case some .class files escape:
|
||||||
|
*.class
|
||||||
|
@ -17,21 +17,29 @@ import spaceshipsim.entities.*;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class SpaceShipSim extends JFrame implements Runnable, KeyListener {
|
public class SpaceShipSim extends JFrame implements Runnable, KeyListener {
|
||||||
private final String version = "v0.1";
|
private final String version = "v0.2";
|
||||||
|
|
||||||
|
// Menu items
|
||||||
|
JMenuBar menuBar;
|
||||||
|
JMenu simulationMenu;
|
||||||
|
JMenuItem exitMenuItem;
|
||||||
|
|
||||||
|
// Graphics/Framework items
|
||||||
private Thread gameloop;
|
private Thread gameloop;
|
||||||
private BufferedImage backbuffer;
|
private BufferedImage backbuffer;
|
||||||
private Graphics2D g2d;
|
private Graphics2D g2d;
|
||||||
private AffineTransform identity = new AffineTransform();
|
private AffineTransform identity = new AffineTransform();
|
||||||
|
|
||||||
|
// The Ship
|
||||||
private Ship ship;
|
private Ship ship;
|
||||||
|
|
||||||
// Constructor:
|
// Constructor:
|
||||||
public SpaceShipSim() {
|
public SpaceShipSim() {
|
||||||
super("Space Ship Simulator");
|
super("Space Ship Simulator");
|
||||||
setSize(800, 600);
|
|
||||||
setVisible(true);
|
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
setSize(800, 600);
|
||||||
|
menuSetup();
|
||||||
|
setVisible(true);
|
||||||
|
|
||||||
backbuffer = new BufferedImage(800, 600, BufferedImage.TYPE_INT_RGB);
|
backbuffer = new BufferedImage(800, 600, BufferedImage.TYPE_INT_RGB);
|
||||||
g2d = backbuffer.createGraphics();
|
g2d = backbuffer.createGraphics();
|
||||||
@ -42,6 +50,22 @@ public class SpaceShipSim extends JFrame implements Runnable, KeyListener {
|
|||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void menuSetup() {
|
||||||
|
menuBar = new JMenuBar();
|
||||||
|
simulationMenu = new JMenu("Simulation");
|
||||||
|
exitMenuItem = new JMenuItem("Exit");
|
||||||
|
|
||||||
|
exitMenuItem.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent ae) {
|
||||||
|
stop();
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
menuBar.add(simulationMenu);
|
||||||
|
this.setJMenuBar(menuBar);
|
||||||
|
}
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
gameloop = new Thread(this);
|
gameloop = new Thread(this);
|
||||||
gameloop.start();
|
gameloop.start();
|
||||||
@ -95,7 +119,6 @@ public class SpaceShipSim extends JFrame implements Runnable, KeyListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void keyPressed(KeyEvent ke) {
|
public void keyPressed(KeyEvent ke) {
|
||||||
//keys[ke.getKeyCode()] = true;
|
|
||||||
int keyCode = ke.getKeyCode();
|
int keyCode = ke.getKeyCode();
|
||||||
|
|
||||||
if(keyCode == KeyEvent.VK_UP) { ship.setAccelerate(true); }
|
if(keyCode == KeyEvent.VK_UP) { ship.setAccelerate(true); }
|
||||||
@ -112,4 +135,4 @@ public class SpaceShipSim extends JFrame implements Runnable, KeyListener {
|
|||||||
public void keyTyped(KeyEvent ke) {}
|
public void keyTyped(KeyEvent ke) {}
|
||||||
|
|
||||||
public static void main(String[] args) { new SpaceShipSim(); }
|
public static void main(String[] args) { new SpaceShipSim(); }
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user