📄 changechatpasswordjdialog.java
字号:
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Copyright (C) 2009 Yan Cheng Cheok <yccheok@yahoo.com>
*/
package org.yccheok.jstock.gui;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
/**
*
* @author yccheok
*/
public class ChangeChatPasswordJDialog extends javax.swing.JDialog {
/** Creates new form ChangeChatPasswordJDialog */
public ChangeChatPasswordJDialog(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
this.jLabel3.setVisible(false);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jXHeader1 = new org.jdesktop.swingx.JXHeader();
jPanel1 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jPasswordField1 = new javax.swing.JPasswordField();
jPasswordField2 = new javax.swing.JPasswordField();
jLabel3 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
setTitle("Market Chit Chat Password");
setResizable(false);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}
});
jXHeader1.setDescription("Change your market chit chat account password");
jXHeader1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/32x32/ksmiletris.png"))); // NOI18N
jXHeader1.setTitle("Market Chit Chat Password");
getContentPane().add(jXHeader1, java.awt.BorderLayout.NORTH);
jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/16x16/apply.png"))); // NOI18N
jButton1.setText("OK");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel1.add(jButton1);
jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/16x16/button_cancel.png"))); // NOI18N
jButton2.setText("Cancel");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jPanel1.add(jButton2);
getContentPane().add(jPanel1, java.awt.BorderLayout.SOUTH);
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Change Password"));
jLabel1.setText("New Password");
jLabel2.setText("Re-type New Password");
jLabel3.setText("Please wait while your new password is being submitted to server...");
jLabel3.setForeground(new java.awt.Color(0, 0, 255));
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2))
.addGap(35, 35, 35)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jPasswordField2)
.addComponent(jPasswordField1, javax.swing.GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE))
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addGap(37, 37, 37)
.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(32, 32, 32))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jPasswordField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel3)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-423)/2, (screenSize.height-240)/2, 423, 240);
}// </editor-fold>//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
final char[] password1 = this.jPasswordField1.getPassword();
final char[] password2 = this.jPasswordField2.getPassword();
if (password1 == null || password1.length <= 0) {
JOptionPane.showMessageDialog(this, "Password field may not be empty.", "Empty password", JOptionPane.WARNING_MESSAGE);
this.jPasswordField1.requestFocus();
return;
}
if (password2 == null || password2.length <= 0) {
JOptionPane.showMessageDialog(this, "Password field may not be empty.", "Empty password", JOptionPane.WARNING_MESSAGE);
this.jPasswordField2.requestFocus();
return;
}
final String newPassword = new String(password1);
final String newPassword2 = new String(password2);
if (newPassword.equals(newPassword2) == false) {
JOptionPane.showMessageDialog(this, "\"Re-type New Password\" field must be same as \"New Password\" field", "Re-type password", JOptionPane.WARNING_MESSAGE);
this.jPasswordField2.requestFocus();
return;
}
if (newPassword.equals(Utils.decrypt(MainFrame.getJStockOptions().getChatPassword())))
{
JOptionPane.showMessageDialog(this, "New password cannot same as old password.", "Re-type password", JOptionPane.WARNING_MESSAGE);
this.jPasswordField2.requestFocus();
return;
}
this.thread = new Thread(new Runnable() {
@Override
public void run() {
if (MainFrame.getMe().changeChatPassword(newPassword))
{
MainFrame.getJStockOptions().setChatPassword(Utils.encrypt(newPassword));
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JOptionPane.showMessageDialog(ChangeChatPasswordJDialog.this, "Market Chit Chat password has been changed successfully. You will be re-login again", "Password changed", JOptionPane.INFORMATION_MESSAGE);
returnCode = true;
ChangeChatPasswordJDialog.this.dispose();
}
});
}
}
});
jLabel3.setVisible(true);
jButton1.setEnabled(false);
jButton2.setEnabled(false);
this.thread.start();
}//GEN-LAST:event_jButton1ActionPerformed
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
returnCode = false;
this.setVisible(false);
this.dispose();
}//GEN-LAST:event_jButton2ActionPerformed
private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
// TODO add your handling code here:
if (thread != null) return;
returnCode = false;
this.setVisible(false);
this.dispose();
}//GEN-LAST:event_formWindowClosing
public boolean doModal() {
this.setVisible(true);
return returnCode;
}
private Thread thread = null;
private boolean returnCode = false;
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPasswordField jPasswordField1;
private javax.swing.JPasswordField jPasswordField2;
private org.jdesktop.swingx.JXHeader jXHeader1;
// End of variables declaration//GEN-END:variables
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -