diff --git a/MooBreeder.java b/MooBreeder.java index f42421a..093eb42 100755 --- a/MooBreeder.java +++ b/MooBreeder.java @@ -11,8 +11,6 @@ * This is the main class with the GUI. */ -//TODO Set breeding goal at beginning of game (dairy, meat, plowing) - import java.awt.*; import java.awt.event.*; import javax.swing.*; @@ -23,7 +21,8 @@ public class MooBreeder extends JFrame implements MouseListener { - private String goal; //TODO implement goal picking + private static final String VERSION = "1.0"; + private String goal; private JMenuBar menubar; private JMenu fileMenu, helpMenu; @@ -33,7 +32,6 @@ private Box herdBox, motherBox, fatherBox, calf1Box, calf2Box; private JButton breedButton; private JFileChooser fileChooser; - private HelpWindow helpWindow; public static void main(String[] args) @@ -131,7 +129,8 @@ quit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.ALT_MASK)); about.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - JOptionPane.showMessageDialog(null, "MooBreeder - an educational breeding game"+ + JOptionPane.showMessageDialog(null, "MooBreeder "+VERSION+ + "\n- an educational breeding game -"+ "\n\n(c) 2018 Daniel Vedder"+ ", Amano Christian School"+ "\nhttps://git.synoikos.de/daniel/moobreeder", @@ -204,7 +203,7 @@ updateHerdBox(); updateParentBox(); updateOffspringBox(); - //this.validate(); + this.validate(); this.repaint(); } @@ -218,8 +217,9 @@ Box cowBox = getCowBox(cow); herdBox.add(cowBox); herdBox.add(Box.createVerticalStrut(1)); - } + } herdScroller.validate(); herdBox.validate(); + herdScroller.validate(); } private void updateParentBox() @@ -332,23 +332,22 @@ private void chooseGoal() { String[] possible = {"dairy", "beef", "plowing"}; - goal = (String) JOptionPane.showInputDialog(null, "What do you want to breed for?", - "Select a goal", JOptionPane.QUESTION_MESSAGE, - null, possible, possible[0]); + Object newGoal = JOptionPane.showInputDialog(null, "What do you want to breed for?", + "Select a goal", JOptionPane.QUESTION_MESSAGE, + null, possible, possible[0]); + if (newGoal != null) goal = (String) newGoal; updateGUI(); } private void resetGame() { Herd.getInstance().resetHerd(); - updateGUI(); //FIXME JScrollPane sometimes disappears until window is resized + updateGUI(); chooseGoal(); } /* * MouseListener methods - * - * FIXME Updating the GUI does not yet work as and when intended */ @Override @@ -393,7 +392,6 @@ JMenuItem item1 = new JMenuItem(); JMenuItem item2 = new JMenuItem(); //Change item labels and actions depending on context - //FIXME Problem with animals occurring both in the herd list and the parent slots item1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { mouseMainAction(selection); //always the same @@ -408,6 +406,7 @@ item2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Herd.getInstance().discardCalf(selection); + updateGUI(); } }); } @@ -421,8 +420,10 @@ int confirm = JOptionPane.showConfirmDialog(null, question, "Remove animal?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); - if(confirm == JOptionPane.YES_OPTION) + if(confirm == JOptionPane.YES_OPTION) { Herd.getInstance().removeCow(selection); + updateGUI(); + } } }); } @@ -430,7 +431,6 @@ contextMenu.add(item1); if (item2.getText() != "") contextMenu.add(item2); contextMenu.show(me.getComponent(), me.getX(), me.getY()); - updateGUI(); } @Override