Datasets:
ArXiv:
License:
File size: 4,160 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 |
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package battleship.gui.Join;
import battleship.Networking.ServerAddress;
import battleship.Networking.ServerManager;
import battleship.Resources.Resources;
import battleship.Utils.Settings;
import java.awt.Font;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
*
* @author nycs0
*/
public class AddEditServer extends JPanel {
private JTextField nameText, ipText, portText;
private JLabel nameLbl, ipLbl, portLbl;
public AddEditServer() {
this(new ServerAddress("", "", Settings.getPort()), true);
}
public AddEditServer(ServerAddress sa) {
this(sa, false);
}
private AddEditServer(ServerAddress sa, boolean add) {
setLayout(null);
setBackground(Resources.BackgroundColor);
Font font = new Font("", Font.BOLD, 12);
nameText = new JTextField();
nameText.setText(sa.getName());
nameText.setLocation(110, 10);
nameText.setSize(300, 35);
nameText.setBackground(Resources.BackgroundColor);
nameText.setFont(font);
this.add(nameText);
ipText = new JTextField();
ipText.setText(sa.getIP());
ipText.setLocation(110, 50);
ipText.setSize(300, 35);
ipText.setBackground(Resources.BackgroundColor);
ipText.setFont(font);
this.add(ipText);
portText = new JTextField();
portText.setText(sa.getPort() + "");
portText.setLocation(110, 90);
portText.setSize(50, 35);
portText.setBackground(Resources.BackgroundColor);
portText.setFont(font);
this.add(portText);
nameLbl = new JLabel();
nameLbl.setText("Server name:");
nameLbl.setSize(100, 35);
nameLbl.setLocation(10, 10);
this.add(nameLbl);
ipLbl = new JLabel();
ipLbl.setText("IP address:");
ipLbl.setSize(100, 35);
ipLbl.setLocation(10, 50);
this.add(ipLbl);
portLbl = new JLabel();
portLbl.setText("Port:");
portLbl.setSize(100, 35);
portLbl.setLocation(10, 90);
this.add(portLbl);
JButton save, back;
save = new JButton();
save.setText("Save");
save.setBounds(10, 200, 100, 35);
save.addActionListener(new ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent ae) {
if (add) {
try {
ServerManager.addServer(new ServerAddress(nameText.getText(), ipText.getText(), Integer.parseInt(portText.getText())));
Settings.WriteFile();
setVisible(false);
} catch (Exception e) {
if (e.getMessage().equals("SZERVER NÉV MÁR LÉTEZIK")) {
nameText.setText(nameText.getText() + " (1)");
}
}
} else {
try {
ServerManager.editServer(sa.getName(), new ServerAddress(nameText.getText(), ipText.getText(), Integer.parseInt(portText.getText())));
Settings.WriteFile();
setVisible(false);
} catch (Exception e) {
if (e.getMessage().equals("SZERVER NÉV MÁR LÉTEZIK")) {
nameText.setText(nameText.getText() + " (1)");
}
}
}
}
});
this.add(save);
back = new JButton();
back.setText("Back");
back.setBounds(10, 245, 100, 35);
back.addActionListener(new ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent ae) {
setVisible(false);
}
});
this.add(back);
}
}
|