Browse Source

Refactored GUI and generated Getters

fleetstorm
Lorenz Hohmann 3 years ago
parent
commit
46d51b2b8b
  1. 183
      src/main/java/de/tims/fleetstorm/gui/GUI.java

183
src/main/java/de/tims/fleetstorm/gui/GUI.java

@ -13,8 +13,18 @@ import javax.swing.border.MatteBorder;
public class GUI extends JPanel { public class GUI extends JPanel {
private ArrayList<JPanel> fields; private ArrayList<JPanel> fields;
public GUI() {
private JLabel matchfieldValue;
private JLabel moveValue;
private JLabel own2Ship;
private JLabel own3Ship;
private JLabel own4Ship;
private JLabel own5Ship;
private JLabel enemy2Ship;
private JLabel enemy3Ship;
private JLabel enemy4Ship;
private JLabel enemy5Ship;
public GUI(int gapToFrameBorder, int fieldWidth, int spaceBetween) {
this.fields = new ArrayList<>(); this.fields = new ArrayList<>();
setSize(640, 480); setSize(640, 480);
@ -34,128 +44,129 @@ public class GUI extends JPanel {
infoWrapper.add(yourFleet); infoWrapper.add(yourFleet);
yourFleet.setLayout(null); yourFleet.setLayout(null);
JPanel panel_1 = new JPanel();
panel_1.setBounds(0, 0, 228, 27);
yourFleet.add(panel_1);
panel_1.setLayout(null);
JPanel ownFleetHeadingPanel = new JPanel();
ownFleetHeadingPanel.setBounds(0, 0, 228, 27);
yourFleet.add(ownFleetHeadingPanel);
ownFleetHeadingPanel.setLayout(null);
JLabel ownFleetHeading = new JLabel("Deine Flotte:"); JLabel ownFleetHeading = new JLabel("Deine Flotte:");
ownFleetHeading.setBounds(0, 0, 228, 17); ownFleetHeading.setBounds(0, 0, 228, 17);
panel_1.add(ownFleetHeading);
ownFleetHeadingPanel.add(ownFleetHeading);
ownFleetHeading.setFont(new Font("Tahoma", Font.BOLD, 14)); ownFleetHeading.setFont(new Font("Tahoma", Font.BOLD, 14));
JPanel panel_2 = new JPanel();
panel_2.setBounds(0, 26, 228, 67);
yourFleet.add(panel_2);
panel_2.setLayout(new GridLayout(0, 2, 0, 3));
JPanel ownFleetContentPanel = new JPanel();
ownFleetContentPanel.setBounds(0, 26, 228, 67);
yourFleet.add(ownFleetContentPanel);
ownFleetContentPanel.setLayout(new GridLayout(0, 2, 0, 3));
JLabel own2ShipLabel = new JLabel("1x2 Schiff"); JLabel own2ShipLabel = new JLabel("1x2 Schiff");
panel_2.add(own2ShipLabel);
ownFleetContentPanel.add(own2ShipLabel);
JLabel own2Ship = new JLabel("OK");
panel_2.add(own2Ship);
own2Ship = new JLabel("OK");
ownFleetContentPanel.add(own2Ship);
JLabel own3ShipLabel = new JLabel("1x3 Schiff"); JLabel own3ShipLabel = new JLabel("1x3 Schiff");
panel_2.add(own3ShipLabel);
ownFleetContentPanel.add(own3ShipLabel);
JLabel own3Ship = new JLabel("OK");
panel_2.add(own3Ship);
own3Ship = new JLabel("OK");
ownFleetContentPanel.add(own3Ship);
JLabel own4ShipLabel = new JLabel("1x4 Schiff"); JLabel own4ShipLabel = new JLabel("1x4 Schiff");
panel_2.add(own4ShipLabel);
ownFleetContentPanel.add(own4ShipLabel);
JLabel own4Ship = new JLabel("OK");
panel_2.add(own4Ship);
own4Ship = new JLabel("OK");
ownFleetContentPanel.add(own4Ship);
JLabel own5ShipLabel = new JLabel("1x5 Schiff"); JLabel own5ShipLabel = new JLabel("1x5 Schiff");
panel_2.add(own5ShipLabel);
ownFleetContentPanel.add(own5ShipLabel);
JLabel own5Ship = new JLabel("OK");
panel_2.add(own5Ship);
own5Ship = new JLabel("OK");
ownFleetContentPanel.add(own5Ship);
JPanel enemyFleet = new JPanel(); JPanel enemyFleet = new JPanel();
enemyFleet.setLayout(null); enemyFleet.setLayout(null);
enemyFleet.setBounds(10, 237, 228, 93); enemyFleet.setBounds(10, 237, 228, 93);
infoWrapper.add(enemyFleet); infoWrapper.add(enemyFleet);
JPanel panel_1_1 = new JPanel();
panel_1_1.setLayout(null);
panel_1_1.setBounds(0, 0, 228, 27);
enemyFleet.add(panel_1_1);
JPanel enemyFleetHeadingPanel = new JPanel();
enemyFleetHeadingPanel.setLayout(null);
enemyFleetHeadingPanel.setBounds(0, 0, 228, 27);
enemyFleet.add(enemyFleetHeadingPanel);
JLabel enemyFleetHeading = new JLabel("Gegnerische Flotte:"); JLabel enemyFleetHeading = new JLabel("Gegnerische Flotte:");
enemyFleetHeading.setFont(new Font("Tahoma", Font.BOLD, 14)); enemyFleetHeading.setFont(new Font("Tahoma", Font.BOLD, 14));
enemyFleetHeading.setBounds(0, 0, 228, 17); enemyFleetHeading.setBounds(0, 0, 228, 17);
panel_1_1.add(enemyFleetHeading);
enemyFleetHeadingPanel.add(enemyFleetHeading);
JPanel panel_2_1 = new JPanel();
panel_2_1.setBounds(0, 26, 228, 67);
enemyFleet.add(panel_2_1);
panel_2_1.setLayout(new GridLayout(0, 2, 0, 3));
JPanel enemyFleetContentPanel = new JPanel();
enemyFleetContentPanel.setBounds(0, 26, 228, 67);
enemyFleet.add(enemyFleetContentPanel);
enemyFleetContentPanel.setLayout(new GridLayout(0, 2, 0, 3));
JLabel enemy2ShipLabel = new JLabel("1x2 Schiff"); JLabel enemy2ShipLabel = new JLabel("1x2 Schiff");
panel_2_1.add(enemy2ShipLabel);
enemyFleetContentPanel.add(enemy2ShipLabel);
JLabel enemy2Ship = new JLabel("OK");
panel_2_1.add(enemy2Ship);
enemy2Ship = new JLabel("OK");
enemyFleetContentPanel.add(enemy2Ship);
JLabel enemy3ShipLabel = new JLabel("1x3 Schiff"); JLabel enemy3ShipLabel = new JLabel("1x3 Schiff");
panel_2_1.add(enemy3ShipLabel);
enemyFleetContentPanel.add(enemy3ShipLabel);
JLabel enemy3Ship = new JLabel("OK");
panel_2_1.add(enemy3Ship);
enemy3Ship = new JLabel("OK");
enemyFleetContentPanel.add(enemy3Ship);
JLabel enemy4ShipLabel = new JLabel("1x4 Schiff"); JLabel enemy4ShipLabel = new JLabel("1x4 Schiff");
panel_2_1.add(enemy4ShipLabel);
enemyFleetContentPanel.add(enemy4ShipLabel);
JLabel enemy4Ship = new JLabel("OK");
panel_2_1.add(enemy4Ship);
enemy4Ship = new JLabel("OK");
enemyFleetContentPanel.add(enemy4Ship);
JLabel enemy5ShipLabel = new JLabel("1x5 Schiff"); JLabel enemy5ShipLabel = new JLabel("1x5 Schiff");
panel_2_1.add(enemy5ShipLabel);
enemyFleetContentPanel.add(enemy5ShipLabel);
JLabel enemy5Ship = new JLabel("OK");
panel_2_1.add(enemy5Ship);
enemy5Ship = new JLabel("OK");
enemyFleetContentPanel.add(enemy5Ship);
JPanel infos = new JPanel(); JPanel infos = new JPanel();
infos.setLayout(null); infos.setLayout(null);
infos.setBounds(10, 11, 228, 68); infos.setBounds(10, 11, 228, 68);
infoWrapper.add(infos); infoWrapper.add(infos);
JPanel panel_1_2 = new JPanel();
panel_1_2.setLayout(null);
panel_1_2.setBounds(0, 0, 228, 27);
infos.add(panel_1_2);
JPanel gameInfoHeadingPanel = new JPanel();
gameInfoHeadingPanel.setLayout(null);
gameInfoHeadingPanel.setBounds(0, 0, 228, 27);
infos.add(gameInfoHeadingPanel);
JLabel gameInfoHeading = new JLabel("Spielinfos"); JLabel gameInfoHeading = new JLabel("Spielinfos");
gameInfoHeading.setFont(new Font("Tahoma", Font.BOLD, 14)); gameInfoHeading.setFont(new Font("Tahoma", Font.BOLD, 14));
gameInfoHeading.setBounds(0, 0, 228, 17); gameInfoHeading.setBounds(0, 0, 228, 17);
panel_1_2.add(gameInfoHeading);
gameInfoHeadingPanel.add(gameInfoHeading);
JPanel panel_2_2 = new JPanel();
panel_2_2.setBounds(0, 26, 228, 31);
infos.add(panel_2_2);
panel_2_2.setLayout(new GridLayout(0, 2, 0, 3));
JPanel gameInfoContentPanel = new JPanel();
gameInfoContentPanel.setBounds(0, 26, 228, 31);
infos.add(gameInfoContentPanel);
gameInfoContentPanel.setLayout(new GridLayout(0, 2, 0, 3));
JLabel matchfieldLabel = new JLabel("Spielfeld"); JLabel matchfieldLabel = new JLabel("Spielfeld");
panel_2_2.add(matchfieldLabel);
gameInfoContentPanel.add(matchfieldLabel);
JLabel matchfieldValue = new JLabel("Eigenes");
panel_2_2.add(matchfieldValue);
matchfieldValue = new JLabel("Eigenes");
gameInfoContentPanel.add(matchfieldValue);
JLabel moveLabel = new JLabel("Am Zug"); JLabel moveLabel = new JLabel("Am Zug");
panel_2_2.add(moveLabel);
JLabel moveValue = new JLabel("Du");
panel_2_2.add(moveValue);
gameInfoContentPanel.add(moveLabel);
int gap = 30;
int width = 28;
moveValue = new JLabel("Du");
gameInfoContentPanel.add(moveValue);
for (int x = 0; x < 10; x++) { for (int x = 0; x < 10; x++) {
for (int y = 0; y < 10; y++) { for (int y = 0; y < 10; y++) {
JPanel field = new JPanel(); JPanel field = new JPanel();
field.setBounds(gap + x * width, gap + y * width, width, width);
int xPos = gapToFrameBorder + x * fieldWidth + (x * spaceBetween);
int yPos = gapToFrameBorder + y * fieldWidth + (y * spaceBetween);
field.setBounds(xPos, yPos, fieldWidth, fieldWidth);
field.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0))); field.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0)));
fields.add(field); fields.add(field);
fieldWrapper.add(field); fieldWrapper.add(field);
@ -164,12 +175,56 @@ public class GUI extends JPanel {
} }
public ArrayList<JPanel> getFields() {
return fields;
}
public JLabel getMatchfieldValue() {
return matchfieldValue;
}
public JLabel getMoveValue() {
return moveValue;
}
public JLabel getOwn2Ship() {
return own2Ship;
}
public JLabel getOwn3Ship() {
return own3Ship;
}
public JLabel getOwn4Ship() {
return own4Ship;
}
public JLabel getOwn5Ship() {
return own5Ship;
}
public JLabel getEnemy2Ship() {
return enemy2Ship;
}
public JLabel getEnemy3Ship() {
return enemy3Ship;
}
public JLabel getEnemy4Ship() {
return enemy4Ship;
}
public JLabel getEnemy5Ship() {
return enemy5Ship;
}
/** /**
* This function is only for testing * This function is only for testing
*/ */
public static void main(String[] args) { public static void main(String[] args) {
JFrame frame = new JFrame("Test GUI"); JFrame frame = new JFrame("Test GUI");
GUI gui = new GUI();
GUI gui = new GUI(15, 28, 1);
frame.setContentPane(gui); frame.setContentPane(gui);
frame.setSize(640, 480); frame.setSize(640, 480);
frame.setResizable(true); frame.setResizable(true);

Loading…
Cancel
Save