diff --git a/src/main/java/com/battleship/gui/Window.form b/src/main/java/com/battleship/gui/Window.form index 37395d6..11b7f35 100644 --- a/src/main/java/com/battleship/gui/Window.form +++ b/src/main/java/com/battleship/gui/Window.form @@ -16,8 +16,8 @@ - - + + @@ -26,8 +26,8 @@ - - + + @@ -36,8 +36,8 @@ - - + + @@ -46,8 +46,8 @@ - - + + @@ -66,8 +66,8 @@ - - + + diff --git a/src/main/java/com/battleship/gui/Window.java b/src/main/java/com/battleship/gui/Window.java index 116301e..f49b047 100644 --- a/src/main/java/com/battleship/gui/Window.java +++ b/src/main/java/com/battleship/gui/Window.java @@ -1,7 +1,6 @@ package com.battleship.gui; import com.battleship.game.playerpack.Player; -import com.battleship.networking.NetworkConnection; import com.battleship.utils.BSConfigFile; import com.intellij.uiDesigner.core.GridConstraints; import com.intellij.uiDesigner.core.GridLayoutManager; @@ -12,12 +11,13 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + public class Window { - /** - * - */ private static final long serialVersionUID = 4453499308378636423L; private JFrame frame; private JPanel panel; @@ -28,10 +28,10 @@ public class Window { private JLabel gameName; private final EventHandler eventHandler = new EventHandler(); + private final String gameVersion = getGameProperty("version"); protected String ip; protected int port; - private NetworkConnection connection; /** * Constructor of the Window class @@ -45,7 +45,7 @@ public Window() { */ private void initUI() { - frame = new JFrame("BattleShip Game"); + frame = new JFrame("BattleShip Game v." + gameVersion); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); @@ -54,6 +54,8 @@ private void initUI() { b_start_join.addActionListener(eventHandler); b_settings.addActionListener(eventHandler); + gameName.setText(gameName.getText() + " v." + gameVersion); + frame.add(panel, BorderLayout.CENTER); frame.pack(); frame.setLocationRelativeTo(null); @@ -67,6 +69,21 @@ private void initPlayer() { Player.setAvatar(BSConfigFile.readProperties("Avatar_Path")); } + private String getGameProperty(String key) { + + Properties properties = new Properties(); + String prop = ""; + + try { + InputStream reader = this.getClass().getResourceAsStream("/properties/version.properties"); + properties.load(reader); + prop = properties.getProperty(key); + } catch (IOException e) { + e.printStackTrace(); + } + return prop; + } + { // GUI initializer generated by IntelliJ IDEA GUI Designer // >>> IMPORTANT!! <<< @@ -86,22 +103,22 @@ private void initPlayer() { panel.setLayout(new GridLayoutManager(5, 3, new Insets(0, 0, 0, 0), -1, -1)); panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10), null, TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, this.$$$getFont$$$(null, -1, -1, panel.getFont()), null)); b_start_host = new JButton(); - b_start_host.setIcon(new ImageIcon(getClass().getResource("/server.png"))); + b_start_host.setIcon(new ImageIcon(getClass().getResource("/images/server.png"))); b_start_host.setText("Host Game"); b_start_host.setToolTipText("Host a game"); panel.add(b_start_host, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); b_start_join = new JButton(); - b_start_join.setIcon(new ImageIcon(getClass().getResource("/link.png"))); + b_start_join.setIcon(new ImageIcon(getClass().getResource("/images/link.png"))); b_start_join.setText("Join Game"); b_start_join.setToolTipText("Join a game"); panel.add(b_start_join, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); b_settings = new JButton(); - b_settings.setIcon(new ImageIcon(getClass().getResource("/settings.png"))); + b_settings.setIcon(new ImageIcon(getClass().getResource("/images/settings.png"))); b_settings.setText("Settings"); b_settings.setToolTipText("Open the settings"); panel.add(b_settings, new GridConstraints(3, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); b_exit = new JButton(); - b_exit.setIcon(new ImageIcon(getClass().getResource("/logout.png"))); + b_exit.setIcon(new ImageIcon(getClass().getResource("/images/logout.png"))); b_exit.setText("Exit"); b_exit.setToolTipText("Exit the application"); panel.add(b_exit, new GridConstraints(4, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); @@ -110,8 +127,8 @@ private void initPlayer() { final Spacer spacer2 = new Spacer(); panel.add(spacer2, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); gameName = new JLabel(); - gameName.setIcon(new ImageIcon(getClass().getResource("/ship.png"))); - gameName.setText("BattleShip game v.0.0.1"); + gameName.setIcon(new ImageIcon(getClass().getResource("/images/ship.png"))); + gameName.setText("BattleShip game"); panel.add(gameName, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); } diff --git a/src/main/resources/anonymous.png b/src/main/resources/images/anonymous.png similarity index 100% rename from src/main/resources/anonymous.png rename to src/main/resources/images/anonymous.png diff --git a/src/main/resources/avatar.png b/src/main/resources/images/avatar.png similarity index 100% rename from src/main/resources/avatar.png rename to src/main/resources/images/avatar.png diff --git a/src/main/resources/link.png b/src/main/resources/images/link.png similarity index 100% rename from src/main/resources/link.png rename to src/main/resources/images/link.png diff --git a/src/main/resources/logout.png b/src/main/resources/images/logout.png similarity index 100% rename from src/main/resources/logout.png rename to src/main/resources/images/logout.png diff --git a/src/main/resources/server.png b/src/main/resources/images/server.png similarity index 100% rename from src/main/resources/server.png rename to src/main/resources/images/server.png diff --git a/src/main/resources/settings.png b/src/main/resources/images/settings.png similarity index 100% rename from src/main/resources/settings.png rename to src/main/resources/images/settings.png diff --git a/src/main/resources/ship.png b/src/main/resources/images/ship.png similarity index 100% rename from src/main/resources/ship.png rename to src/main/resources/images/ship.png diff --git a/src/main/resources/properties/version.properties b/src/main/resources/properties/version.properties new file mode 100644 index 0000000..6a4278c --- /dev/null +++ b/src/main/resources/properties/version.properties @@ -0,0 +1,3 @@ +artifactId=BattleShip +groupId=com.battleship +version=1.0-SNAPSHOT