Datasets:

ArXiv:
License:
File size: 6,586 Bytes
c574d3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
//Csaba
package battleship.gui;

import battleship.Events.JoinGUIEvent;
import battleship.Networking.ServerAddress;
import battleship.Resources.Resources;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author Csaba
 */
public class MenuGUI extends JFrame {

    public static int WindowInsets;
    JButton newGame, joinGame, settingsButton, exitButton;
    JPanel menu;
    boolean dontShowMenu;

    public MenuGUI() {
        this.setSize(800, 600);
        this.setResizable(false);
        this.setTitle("BattleShip");
        this.setLayout(null);
        this.setVisible(true);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        WindowInsets = this.insets().top;

        menu = new JPanel();
        menu.setBackground(Resources.BackgroundColor);
        menu.setLayout(null);
        menu.setBounds(0, 0, 800, 600);
        this.add(menu);

        int buttonWidth = 100;
        int buttonHeight = 35;

        JLabel title = new JLabel();
        title.setText("Battleship game");
        title.setFont(new Font("Dialog", Font.BOLD, 30));
        title.setHorizontalAlignment(JLabel.CENTER);
        title.setVerticalTextPosition(JLabel.CENTER);
        title.setHorizontalTextPosition(JLabel.CENTER);
        title.setSize(800, 100);
        title.setLocation(0, 0);
        menu.add(title);

        newGame = new JButton();
        newGame.setText("New game");
        newGame.setSize(buttonWidth, buttonHeight);
        newGame.setLocation((this.size().width - buttonWidth) / 2, 222);
        newGame.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent ae) {
                //System.out.println("new");
                menu.setVisible(false);
                //gameGUI.setVisible(true);
                createGameGUI(null);
            }
        });
        menu.add(newGame);

        dontShowMenu = false;
        JoinGUI joinGUI = new JoinGUI();
        joinGUI.setBounds(0, 0, this.size().width, this.size().height);
        joinGUI.setVisible(false);
        joinGUI.addComponentListener(new ComponentAdapter() {
            public void componentHidden(ComponentEvent e) {
                if (!dontShowMenu) {
                    menu.setVisible(true);
                }
            }
        });
        joinGUI.AddConnectListener(new JoinGUIEvent() {
            @Override
            public void onConnect(ServerAddress serverAddress) {
                System.out.println("Join");
                joinGUI.setVisible(false);
                dontShowMenu = true;
                createGameGUI(serverAddress);
            }
        });
        this.add(joinGUI);

        joinGame = new JButton();
        joinGame.setText("Join game");
        joinGame.setSize(buttonWidth, buttonHeight);
        joinGame.setLocation((this.size().width - buttonWidth) / 2, 262);
        joinGame.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent ae) {
                //System.out.println("join");
                dontShowMenu = false;
                menu.setVisible(false);
                joinGUI.setVisible(true);
            }
        });
        menu.add(joinGame);

        SettingsGUI settingsGUI = new SettingsGUI();
        settingsGUI.setBounds(0, 0, this.size().width, this.size().height);
        settingsGUI.setVisible(false);
        settingsGUI.addComponentListener(new ComponentAdapter() {
            public void componentHidden(ComponentEvent e) {
                if (!dontShowMenu) {
                    menu.setVisible(true);
                }
            }
        });
        this.add(settingsGUI);

        settingsButton = new JButton();
        settingsButton.setText("Settings");
        settingsButton.setSize(buttonWidth, buttonHeight);
        settingsButton.setLocation((this.size().width - buttonWidth) / 2, 302);
        settingsButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent ae) {
                menu.setVisible(false);
                settingsGUI.setVisible(true);
            }
        });
        menu.add(settingsButton);

        exitButton = new JButton();
        exitButton.setText("Exit");
        exitButton.setSize(buttonWidth, buttonHeight);
        exitButton.setLocation((this.size().width - buttonWidth) / 2, 342);
        exitButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent ae) {
                //System.out.println("exitButton");
                System.exit(0);
            }
        });
        menu.add(exitButton);

        TesztGUI t = new TesztGUI();
        t.setVisible(false);
        t.addComponentListener(new ComponentAdapter() {
            public void componentShown(ComponentEvent e) {

            }

            public void componentHidden(ComponentEvent e) {
                menu.setVisible(true);
            }
        });
        this.add(t);

        JButton tesztButton = new JButton();
        tesztButton.setText("teszt környezet");
        tesztButton.setBounds(10, 10, 150, 40);
        tesztButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent ae) {
                //System.out.println("tesztButton lenyomva");
                menu.setVisible(false);
                t.setVisible(true);
            }
        });
        menu.add(tesztButton);
        repaint();
    }

    private void createGameGUI(ServerAddress sa) {
        GameGUI gameGUI;
        if (sa != null) {
            gameGUI = new GameGUI(sa.getIP(), sa.getPort());
        } else {
            gameGUI = new GameGUI();
        }
        gameGUI.setBounds(0, 0, this.size().width, this.size().height);
        //gameGUI.setVisible(false);
        gameGUI.addComponentListener(new ComponentAdapter() {
            public void componentShown(ComponentEvent e) {
                menu.setVisible(false);
            }

            public void componentHidden(ComponentEvent e) {
                menu.setVisible(true);
                remove(gameGUI);
            }
        });
        menu.setVisible(false);
        this.add(gameGUI);
    }
}