⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loginsettingspanel.java

📁 一个类似QQ的在线通讯聊天软件原码,适合初学者参考学习。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
  /**   * (non-Javadoc)   * @see org.javalib.gui.model.SettingsDisplayPanel#getSaveSettingsErrorTitle()   */  public String getSaveSettingsErrorTitle()  {    return ((String[]) SettingsDialog.localized.get("messageTitles"))[0];  }  /**   * (non-Javadoc)   * @see org.javalib.gui.model.SettingsDisplayPanel#hasChanged()   */  public boolean hasChanged()  {    synchronized (Start.env)    {      if (String.valueOf(jPasswordFieldOldPw.getPassword()).equals("")          && String.valueOf(jPasswordFieldNewPw1.getPassword()).equals("")          && String.valueOf(jPasswordFieldNewPw2.getPassword()).equals("")          && ((jCheckBoxAutoLogin.isSelected()               && jCheckBoxAutoSave.isSelected() && Start.env.getLoginMode() == Oscar.AUTOLOGIN)              || (!jCheckBoxAutoLogin.isSelected()                  && jCheckBoxAutoSave.isSelected() && Start.env.getLoginMode() == Oscar.AUTOSAVE) || (!jCheckBoxAutoLogin.isSelected()                                                                                                       && !jCheckBoxAutoSave.isSelected() && Start.env.getLoginMode() == Oscar.NOAUTO))          && Start.env.getHost().equals(jTextFieldHost.getText())          && Start.env.getPort() == wholeNumberFieldPort.getValue())      {        return false;      }    }    return true;  }  /**   * (non-Javadoc)   * @see org.javalib.gui.model.SettingsDisplayPanel#loadSettings()   */  public void loadSettings()  {    synchronized (Start.env)    {      switch (Start.env.getLoginMode())      {        case Oscar.AUTOLOGIN:          this.jCheckBoxAutoLogin.setSelected(true);          this.jCheckBoxAutoLogin.setEnabled(true);          this.jCheckBoxAutoSave.setSelected(true);          this.jCheckBoxAutoSave.setEnabled(false);          break;        case Oscar.AUTOSAVE:          this.jCheckBoxAutoLogin.setSelected(false);          this.jCheckBoxAutoLogin.setEnabled(false);          this.jCheckBoxAutoSave.setSelected(true);          this.jCheckBoxAutoSave.setEnabled(true);          break;        case Oscar.NOAUTO:          this.jCheckBoxAutoLogin.setSelected(false);          this.jCheckBoxAutoLogin.setEnabled(true);          this.jCheckBoxAutoSave.setSelected(false);          this.jCheckBoxAutoSave.setEnabled(true);          break;      }      this.jTextFieldHost.setText(Start.env.getHost());      this.wholeNumberFieldPort.setValue(Start.env.getPort());    }    this.jPasswordFieldOldPw.setText("");    this.jPasswordFieldNewPw1.setText("");    this.jPasswordFieldNewPw2.setText("");  }  /**   * (non-Javadoc)   * @see org.javalib.gui.model.SettingsDisplayPanel#saveSettings()   */  public void saveSettings() throws Exception  {    String msg, title;    if (jTextFieldHost.getText().equals(""))    {      msg = ((String[]) SettingsDialog.localized.get("errorMessages"))[20];      title = ((String[]) SettingsDialog.localized.get("messageTitles"))[0];      JOptionPane.showMessageDialog(parent, msg, title,                                    JOptionPane.ERROR_MESSAGE);      return;    }    if (wholeNumberFieldPort.getValue() < 1        || wholeNumberFieldPort.getValue() > 65535)    {      msg = ((String[]) SettingsDialog.localized.get("errorMessages"))[2];      title = ((String[]) SettingsDialog.localized.get("messageTitles"))[0];      JOptionPane.showMessageDialog(parent, msg, title,                                    JOptionPane.ERROR_MESSAGE);      return;    }    synchronized (Start.env)    {      Start.env.setHost(jTextFieldHost.getText());      Start.env.setPort((int) wholeNumberFieldPort.getValue());      // Save login info      try      {        int loginMode;        String password;        if (jCheckBoxAutoLogin.isSelected())        {          loginMode = Oscar.AUTOLOGIN;          password = Start.env.getPassword();        }        else if (jCheckBoxAutoSave.isSelected())        {          loginMode = Oscar.AUTOSAVE;          password = Start.env.getPassword();        }        else        {          loginMode = Oscar.NOAUTO;          password = "";        }        CryptFile.write(Default.FOLDER_NAME_HOME + "/"                        + Start.env.getOwnContact().getContactId() + "/"                        + Default.FILE_NAME_LOGIN_DATA, new String[]        {         Start.env.getHost(),         String.valueOf(Start.env.getPort()),         password,         String.valueOf(loginMode)        });        Start.env.setLoginMode(loginMode);      }      catch (Exception ex)      {        msg = ((String[]) SettingsDialog.localized.get("errorMessages"))[11];        throw new Exception(msg);      }      // Change password      String oldpw = String.valueOf(jPasswordFieldOldPw.getPassword());      String newpw1 = String.valueOf(jPasswordFieldNewPw1.getPassword());      String newpw2 = String.valueOf(jPasswordFieldNewPw2.getPassword());      if (Start.env.getConnection() != null          && Start.env.getConnection().isLogged()          && (!oldpw.equals("") || !newpw1.equals("") || !newpw2.equals("")))      {        if (!Start.env.getPassword().equals(oldpw))        {          jPasswordFieldOldPw.setText("");          msg = ((String[]) SettingsDialog.localized.get("errorMessages"))[4];          throw new Exception(msg);        }        if (!newpw1.equals(newpw2))        {          jPasswordFieldNewPw1.setText("");          jPasswordFieldNewPw2.setText("");          msg = ((String[]) SettingsDialog.localized.get("errorMessages"))[3];          throw new Exception(msg);        }        if (newpw1.length() < Default.MIN_PASSWORD_LEN)        {          msg = ((String[]) SettingsDialog.localized.get("errorMessages"))[6];          throw new Exception(msg);        }        int ownID = Integer.parseInt(Start.env.getOwnContact().getContactId());        final char[] newPw = jPasswordFieldNewPw1.getPassword();        jPasswordFieldOldPw.setText("");        jPasswordFieldNewPw1.setText("");        jPasswordFieldNewPw2.setText("");        new ChangePasswordRequest(Start.env.getConnection(), ownID, newPw)        {          public void onResponse(int success)          {            int loginMode;            String msg, title;            String password = String.valueOf(newPw);            if (success != Flag.SUCCESS)            {              msg = ((String[]) SettingsDialog.localized.get("errorMessages"))[21];              title = ((String[]) SettingsDialog.localized.get("messageTitles"))[0];              JOptionPane.showMessageDialog(parent, msg, title,                                            JOptionPane.ERROR_MESSAGE);              return;            }            synchronized (Start.env)            {              Start.env.setPassword(password);              try              {                if (Start.env.getLoginMode() == Oscar.AUTOLOGIN)                {                  loginMode = Oscar.AUTOLOGIN;                }                else if (Start.env.getLoginMode() == Oscar.AUTOSAVE)                {                  loginMode = Oscar.AUTOSAVE;                }                else                {                  loginMode = Oscar.NOAUTO;                  password = "";                }                String path = Default.FOLDER_NAME_HOME + "/"                              + Start.env.getOwnContact().getContactId() + "/"                              + Default.FILE_NAME_LOGIN_DATA;                CryptFile.write(path, new String[]                {                 Start.env.getHost(),                 String.valueOf(Start.env.getPort()),                 password,                 String.valueOf(loginMode)                });                Start.env.setLoginMode(loginMode);              }              catch (Exception ex)              {                msg = ((String[]) SettingsDialog.localized.get("errorMessages"))[11];                title = ((String[]) SettingsDialog.localized.get("messageTitles"))[0];                JOptionPane.showMessageDialog(parent, msg, title,                                              JOptionPane.ERROR_MESSAGE);                return;              }            }          }        };      }    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -