Пример #1
0
  public static void main(String[] args) {

    fileName = dateFormat.format(date);
    try {
      String curDir = System.getProperty("user.dir");
      boolean dirMake = (new File(curDir + "\\Logs\\")).mkdir();
      if (dirMake) {}
      fileWrite = new BufferedWriter(new FileWriter(curDir + "\\Logs\\" + fileName + "log.txt"));
      fileWrite.write("Chat log:" + fileName + "\n");
      fileWrite.flush();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    ChatServer frame = new ChatServer();
    frame.setVisible(true);
    frame.setResizable(false);
    frame.addWindowListener(
        new WindowListener() {
          public void windowClosed(WindowEvent arg0) {
            ClientListener.writeLog();
            System.exit(-1);
          }

          public void windowActivated(WindowEvent arg0) {}

          public void windowClosing(WindowEvent arg0) {
            ClientListener.writeLog();
            System.exit(-1);
          }

          public void windowDeactivated(WindowEvent arg0) {}

          public void windowDeiconified(WindowEvent arg0) {}

          public void windowIconified(WindowEvent arg0) {}

          public void windowOpened(WindowEvent arg0) {}
        });
  }