Datasets:

ArXiv:
License:
File size: 2,466 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
package battleship.gui;

import battleship.Resources.Resources;
import battleship.Utils.Settings;
import java.awt.Color;
import java.awt.Font;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;


public class SettingsGUI extends JPanel {
    private JLabel labelSaved;

    public SettingsGUI() {
        setLayout(null);
        this.setSize(800, 600 - MenuGUI.WindowInsets);
        setBackground(Resources.BackgroundColor);

        JLabel title = new JLabel();
        title.setBackground(Color.red);
        title.setBounds(10, 10, 10, 10);
        this.add(title);
        
        JButton backButton = new JButton();
        backButton.setText("Back to menu");
        backButton.setSize(115, 35);
        backButton.setLocation(10, 10);
        backButton.addActionListener((java.awt.event.ActionEvent ae) -> {
            setVisible(false);
        });
        this.add(backButton);
        
        JLabel labelPort = new JLabel();
        labelPort.setText("Port:");
        labelPort.setSize(115,35);
        labelPort.setLocation(360-(115/2),250);
        this.add(labelPort);
        
        JTextField textPort = new JTextField();
        textPort.setText(String.valueOf(Settings.getPort()));
        textPort.setSize(115, 35);
        textPort.setLocation(400-(115/2),250);
        textPort.addActionListener((java.awt.event.ActionEvent ae) -> {
            TimerTask task = new TimerTask() {
                @Override
                public void run() {
                    labelSaved.setVisible(false);
                }
            };
            labelSaved.setVisible(true);
            Timer timer = new Timer();
            timer.schedule(task, 2000);
            int parsedInt = 25564;
            try {
                parsedInt = Integer.parseInt(textPort.getText());
            }
            catch (NumberFormatException ex) { }
            Settings.setPort(parsedInt);
            Settings.WriteFile();
            
        });
        this.add(textPort);
        
        labelSaved = new JLabel("Settings saved.", JTextField.CENTER);
        labelSaved.setSize(240, 35);
        
        labelSaved.setLocation((size().width-labelSaved.getSize().width)/2, 500);
        labelSaved.setVisible(false);
        labelSaved.setFont(new Font("Dialog", Font.BOLD, 20));  
        this.add(labelSaved);
        
        
    }
}