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