public void init() {
	String serverConnectStr = "Enter server: ";
		while (true) {
			String hostStr = JOptionPane.showInputDialog(serverConnectStr, Connection.DEFAULT_HOST + ":" + String.valueOf(Connection.DEFAULT_PORT));
			if (hostStr == null) {
				return;
			}
			try {
				this.conn = new Connection(hostStr);
				break;
			} catch (NumberFormatException e) {
				serverConnectStr = "Invalid port. Enter server:";
			}
		}

		this.net = new NetManager(conn);
		try {
			net.connectToServer();
			userName = (String) JOptionPane.showInputDialog("Write username!");
			if (userName == null) {
				return;
			} else if (userName.length() == 0) {
				JOptionPane.showMessageDialog(null,
						"Empty user name not allowed.", "Error",
						JOptionPane.ERROR_MESSAGE);
				return;
			}
			InitializeClientMessage icm = new InitializeClientMessage(userName);
			Encoder enc = new Encoder();
			String mess;
			try {
				mess = enc.encode(icm);
				net.send(mess);
			} catch (JSONException e) {
				JOptionPane.showMessageDialog(null, "Can't connect to server!",
						"Warning", JOptionPane.ERROR_MESSAGE);
			}
			this.stage = 1;
			Tick();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}