📄 changeframe.java
字号:
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.*;
import javax.swing.JLabel;
import java.awt.Rectangle;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import java.awt.Dimension;
import java.awt.Toolkit;
//修改个人资料
public class changeFrame extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JLabel changeInfo = null;
private JLabel newaccount = null;
private JLabel changePassword = null;
private JLabel oldpassword = null;
private JTextField newaccount1 = null;
private JPasswordField oldpassword1 = null;
private JLabel newpassword = null;
private JPasswordField newpassword1 = null;
private JLabel affirmpassword = null;
private JPasswordField affirmpassword1 = null;
private JButton submit = null;
private String jing = new String(""); // @jve:decl-index=0:
private JLabel account = null;
private JButton abort = null;
private JLabel jLabel = null;
/**
* This is the default constructor
*/
public changeFrame() {
super();
initialize();
}
public changeFrame(String jing) {
super();
this.jing = jing;
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(325, 317);
this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/pic/info.png")));
this.setContentPane(getJContentPane());
this.setTitle("修改个人资料");
this.setResizable(false);
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(0, 0, 316, 284));
jLabel.setIcon(new ImageIcon(getClass().getResource("/pic/background4.jpg")));
account = new JLabel();
account.setBounds(new Rectangle(18, 83, 20, 15));
account.setIcon(new ImageIcon(getClass().getResource("/pic/account1.png")));
affirmpassword = new JLabel();
affirmpassword.setBounds(new Rectangle(50, 200, 85, 20));
affirmpassword.setText(" 确认新密码");
newpassword = new JLabel();
newpassword.setBounds(new Rectangle(50, 160, 85, 20));
newpassword.setText(" 新密码");
oldpassword = new JLabel();
oldpassword.setBounds(new Rectangle(50, 120, 85, 20));
oldpassword.setText(" 旧密码");
changePassword = new JLabel();
changePassword.setBounds(new Rectangle(18, 123, 20, 15));
changePassword.setIcon(new ImageIcon(getClass().getResource("/pic/password.png")));
changePassword.setText("");
newaccount = new JLabel();
newaccount.setBounds(new Rectangle(50, 80, 85, 20));
newaccount.setText(" 账户号码");
changeInfo = new JLabel();
changeInfo.setBounds(new Rectangle(60, 20, 60, 45));
changeInfo.setIcon(new ImageIcon(getClass().getResource("/pic/user.png")));
changeInfo.setText("");
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.setBackground(Color.white);
jContentPane.add(changeInfo, null);
jContentPane.add(newaccount, null);
jContentPane.add(changePassword, null);
jContentPane.add(oldpassword, null);
jContentPane.add(getNewaccount1(), null);
jContentPane.add(getOldpassword1(), null);
jContentPane.add(newpassword, null);
jContentPane.add(getNewpassword1(), null);
jContentPane.add(affirmpassword, null);
jContentPane.add(getAffirmpassword1(), null);
jContentPane.add(getSubmit(), null);
jContentPane.add(account, null);
jContentPane.add(getAbort(), null);
jContentPane.add(jLabel, null);
}
return jContentPane;
}
/**
* This method initializes newaccount1
*
* @return javax.swing.JTextField
*/
private JTextField getNewaccount1() {
if (newaccount1 == null) {
newaccount1 = new JTextField();
newaccount1.setBounds(new Rectangle(195, 80, 80, 20));
}
return newaccount1;
}
/**
* This method initializes oldpassword1
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getOldpassword1() {
if (oldpassword1 == null) {
oldpassword1 = new JPasswordField();
oldpassword1.setBounds(new Rectangle(195, 120, 80, 20));
}
return oldpassword1;
}
/**
* This method initializes newpassword1
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getNewpassword1() {
if (newpassword1 == null) {
newpassword1 = new JPasswordField();
newpassword1.setBounds(new Rectangle(195, 160, 80, 20));
}
return newpassword1;
}
/**
* This method initializes affirmpassword1
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getAffirmpassword1() {
if (affirmpassword1 == null) {
affirmpassword1 = new JPasswordField();
affirmpassword1.setBounds(new Rectangle(195, 200, 80, 20));
}
return affirmpassword1;
}
private void sign_out()
{
this.dispose();
}
/**
* This method initializes submit
*
* @return javax.swing.JButton
*/
private JButton getSubmit() {
if (submit == null) {
submit = new JButton();
submit.setBounds(new Rectangle(65, 233, 65, 30));
submit.setIcon(new ImageIcon(getClass().getResource("/pic/submit.gif")));
submit.setBorderPainted(false);
submit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
int j = 0;
if(oldpassword1.getText().length()==0&&newpassword1.getText().length()==0&&affirmpassword1.getText().length()==0&&newaccount1.getText().length()==0)
{//数据都没填写而提交,什么都不做
dispose();
j=1;
}
else if((oldpassword1.getText().length()!=0&&newpassword1.getText().length()!=0&&affirmpassword1.getText().length()!=0)&&!newpassword1.getText().trim().equals(affirmpassword1.getText().trim()))
{
String a="两次输入的密码不一致,请重新输入";
messagebox mb=new messagebox(a);
mb.setVisible(true);
j = 1;
}
else if(oldpassword1.getText().length()!=0)
{
if(newpassword1.getText().length()==0)
{
String a="对不起,新密码不能为空";
messagebox mb=new messagebox(a);
mb.setVisible(true);
j = 1;
}
else if(affirmpassword1.getText().length()==0)
{
String a="对不起,确认新密码不能为空";
messagebox mb=new messagebox(a);
mb.setVisible(true);
j = 1;
}
}
else if(newpassword1.getText().length()!=0)
{
if(oldpassword1.getText().length()==0)
{
String a="对不起,旧密码不能为空";
messagebox mb=new messagebox(a);
mb.setVisible(true);
//JOptionPane.showMessageDialog(null,"对不起,旧密码不能为空","error",JOptionPane.INFORMATION_MESSAGE);
j = 1;
}
else if(affirmpassword1.getText().length()==0)
{
String a="对不起,确认新密码不能为空";
messagebox mb=new messagebox(a);
mb.setVisible(true);
j = 1;
}
}
else if(affirmpassword1.getText().length()!=0)
{
if(oldpassword1.getText().length()==0)
{
String a="对不起,旧密码不能为空";
messagebox mb=new messagebox(a);
mb.setVisible(true);
j = 1;
}
if(newpassword1.getText().length()==0)
{
String a="对不起,新密码不能为空";
messagebox mb=new messagebox(a);
mb.setVisible(true);
j = 1;
}
}
else if(!integer.isInteger(newaccount1.getText()))
{
String a="请输入正确的账户号码";
messagebox mb=new messagebox(a);
mb.setVisible(true);
j=1;
}
if(j == 0)
{
try
{
Socket socket;
socket = new Socket("localhost",2000);
PrintWriter toServer = new PrintWriter(socket.getOutputStream(),true);
toServer.println(7);
toServer.println(jing);
toServer.println(newaccount1.getText().trim());
toServer.println(oldpassword1.getText().trim());
toServer.println(newpassword1.getText().trim());
//toServer.println(affirmpassword1.getText().trim());
try
{
ServerSocket serverSocket = new ServerSocket(2011);
Socket fromServer = serverSocket.accept();
DataInputStream isFromServer = new DataInputStream(fromServer.getInputStream());
int i = isFromServer.readInt();
if(i == 1)
{
String a="修改个人资料成功";
messagebox1 mb=new messagebox1(a,6);
mb.setVisible(true);
sign_out();
}
else if(i==-1)
{
String a="对不起,密码错误";
messagebox mb=new messagebox(a);
mb.setVisible(true);
}
serverSocket.close();
}
catch(IOException ex)
{
System.err.println(ex);
}
}
catch(IOException ex)
{
System.err.println(ex);
}
j = 0;
}
}
});
}
return submit;
}
/**
* This method initializes abort
*
* @return javax.swing.JButton
*/
private JButton getAbort() {
if (abort == null) {
abort = new JButton();
abort.setBounds(new Rectangle(190, 233, 65, 30));
abort.setIcon(new ImageIcon(getClass().getResource("/pic/abort.gif")));
abort.setBackground(Color.white);
abort.setBorderPainted(false);
abort.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
dispose();
}
});
}
return abort;
}
} // @jve:decl-index=0:visual-constraint="32,-14"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -