Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement for issue #19 and addition of some mnemonics for Window #26

Merged
merged 1 commit into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/main/java/com/battleship/gui/Window.form
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<icon value="server.png"/>
<text value="Host Game"/>
<icon value="images/server.png"/>
<text value="&amp;Host Game"/>
<toolTipText value="Host a game"/>
</properties>
</component>
Expand All @@ -26,8 +26,8 @@
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<icon value="link.png"/>
<text value="Join Game"/>
<icon value="images/link.png"/>
<text value="&amp;Join Game"/>
<toolTipText value="Join a game"/>
</properties>
</component>
Expand All @@ -36,8 +36,8 @@
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<icon value="settings.png"/>
<text value="Settings"/>
<icon value="images/settings.png"/>
<text value="&amp;Settings"/>
<toolTipText value="Open the settings"/>
</properties>
</component>
Expand All @@ -46,8 +46,8 @@
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<icon value="logout.png"/>
<text value="Exit"/>
<icon value="images/logout.png"/>
<text value="&amp;Exit"/>
<toolTipText value="Exit the application"/>
</properties>
</component>
Expand All @@ -66,8 +66,8 @@
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<icon value="ship.png"/>
<text value="BattleShip game v.0.0.1"/>
<icon value="images/ship.png"/>
<text value="BattleShip game"/>
</properties>
</component>
</children>
Expand Down
41 changes: 29 additions & 12 deletions src/main/java/com/battleship/gui/Window.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -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!! <<<
Expand All @@ -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));
Expand All @@ -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));
}

Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
3 changes: 3 additions & 0 deletions src/main/resources/properties/version.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
artifactId=BattleShip
groupId=com.battleship
version=1.0-SNAPSHOT