Added a Reset button, and a not working About button.
This commit is contained in:
parent
d7911b01c5
commit
f6cfb9c0bc
@ -99,4 +99,8 @@ public class SimPanel extends JPanel implements Runnable, KeyListener {
|
||||
if(keyCode == KeyEvent.VK_RIGHT) { ship.setTurnRight(false); }
|
||||
}
|
||||
public void keyTyped(KeyEvent ke) {}
|
||||
|
||||
public void reset() {
|
||||
ship = new Ship(400, 300);
|
||||
}
|
||||
}
|
@ -16,8 +16,13 @@ public class SpaceShipSim {
|
||||
|
||||
// Menu items
|
||||
JMenuBar menuBar;
|
||||
|
||||
JMenu simulationMenu;
|
||||
JMenuItem exitMenuItem;
|
||||
JMenuItem resetItem;
|
||||
JMenuItem exitItem;
|
||||
|
||||
JMenu helpMenu;
|
||||
JMenuItem aboutItem;
|
||||
|
||||
// Constructor:
|
||||
public SpaceShipSim() {
|
||||
@ -30,24 +35,45 @@ public class SpaceShipSim {
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
// FIXME: There are no errors in compilation or while running, but the menu bar does not appear
|
||||
public void menuSetup() {
|
||||
menuBar = new JMenuBar();
|
||||
simulationMenu = new JMenu("Simulation");
|
||||
exitMenuItem = new JMenuItem("Exit");
|
||||
resetItem = new JMenuItem("Reset");
|
||||
exitItem = new JMenuItem("Exit");
|
||||
helpMenu = new JMenu("Help");
|
||||
aboutItem = new JMenuItem("About");
|
||||
|
||||
exitMenuItem.addActionListener(new ActionListener() {
|
||||
resetItem.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent ae) { panel.reset(); }
|
||||
});
|
||||
exitItem.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent ae) {
|
||||
panel.stop();
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
simulationMenu.add(exitMenuItem);
|
||||
|
||||
aboutItem.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent ae) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
simulationMenu.add(resetItem);
|
||||
simulationMenu.addSeparator();
|
||||
simulationMenu.add(exitItem);
|
||||
|
||||
helpMenu.add(aboutItem);
|
||||
|
||||
menuBar.add(simulationMenu);
|
||||
menuBar.add(helpMenu);
|
||||
|
||||
frame.setJMenuBar(menuBar);
|
||||
}
|
||||
// !!!FIXME-END!!!
|
||||
|
||||
public static void main(String[] args) { new SpaceShipSim(); }
|
||||
}
|
@ -27,7 +27,6 @@ public class Ship extends BaseVectorShape {
|
||||
public Ship(double nx, double ny) {
|
||||
setX(nx);
|
||||
setY(ny);
|
||||
setVelY(-0.5);
|
||||
setShape(new Polygon(shipx, shipy, shipx.length));
|
||||
setAlive(true);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user