updateselfuser.java

来自「企业级的即时通软件。。java语言写的 这是客户端部份。」· Java 代码 · 共 439 行

JAVA
439
字号
package edu.sccp.chat.frame;

import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import com.swtdesigner.SwingResourceManager;

import edu.sccp.chat.action.ToServerProcess;
import edu.sccp.chat.jarClass.JarAllege;
import edu.sccp.chat.tools.Check;

public class UpdateSelfUser {

	private JTextField textField_3;
	private JLabel label_7;
	/**
	 * @param args
	 */
	private ButtonGroup buttonGroup = new ButtonGroup();
	/**
	 * @param args
	 */
	JFrame frame;
	JPanel panel;
	String sex="";
	JLabel label_10;
	JLabel label_11;
	String headpic;
	String[] user;
	public UpdateSelfUser(String[] str)
	{
		user=str;
		headpic=user[11];
		JarAllege.bai();
		initGUI();
	}
	private void initGUI()
	{
		frame=new JFrame("用户个人信息");
		frame.setIconImage(SwingResourceManager.getImage(UpdateSelfUser.class, "/edu/sccp/chat/image/icon.png"));
		frame.addWindowListener(new WindowAdapter() {
			public void windowClosing(final WindowEvent e) {
				frame.dispose();
			}
		});
		frame.getContentPane().setLayout(null);

		final JLabel label = new JLabel();
		label.setText("用户ID:");
		label.setBounds(21, 10, 57, 16);
		frame.getContentPane().add(label);

		final JTextField textField = new JTextField();
		textField.setEditable(false);
		textField.setText(user[0].trim());
		textField.setBounds(69, 8, 143, 21);
		frame.getContentPane().add(textField);

		final JLabel label_1 = new JLabel();
		label_1.setText("用户姓名:");
		label_1.setBounds(8, 32, 70, 16);
		frame.getContentPane().add(label_1);

		final JTextField nameField = new JTextField();
		nameField.setText(user[1].trim());
		nameField.addFocusListener(new FocusAdapter() {
			public void focusGained(final FocusEvent e) {
				if(nameField.getText().length()==0)
				{
					label_10.setText("2-4字符");
				}else
					label_10.setText("");
			}
			public void focusLost(final FocusEvent e) {
				if(nameField.getText().length()==0)
				{
					label_10.setText("不能为空");
				}else
					label_10.setText("");
			}
		});
		nameField.setBounds(69, 32, 143, 21);
		frame.getContentPane().add(nameField);

		final JLabel label_2 = new JLabel();
		label_2.setText("性别:");
		label_2.setBounds(21, 61, 41, 16);
		frame.getContentPane().add(label_2);

		final JRadioButton men = new JRadioButton();
		men.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				sex="男";
			}
		});
		buttonGroup.add(men);
		men.setText("男");
		men.setBounds(62, 59, 45, 25);
		frame.getContentPane().add(men);

		final JRadioButton women = new JRadioButton();
		women.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				sex="女";
			}
		});
		buttonGroup.add(women);
		women.setText("女");
		women.setBounds(112, 59, 63, 25);
		frame.getContentPane().add(women);

		final JLabel label_3 = new JLabel();
		label_3.setText("所属部门:");
		label_3.setBounds(8, 92, 70, 16);
		frame.getContentPane().add(label_3);

		final JTextField textField_2 = new JTextField();
		textField_2.setText(user[4].trim());
		textField_2.setEditable(false);
		textField_2.setBounds(72, 90, 85, 21);
		frame.getContentPane().add(textField_2);

		final JLabel label_4 = new JLabel();
		label_4.setText("联系电话:");
		label_4.setBounds(8, 141, 65, 16);
		frame.getContentPane().add(label_4);

		final JTextField telField = new JTextField();
		telField.setText(user[8].trim());
		telField.addFocusListener(new FocusAdapter() {
			public void focusGained(final FocusEvent e) {
				if(telField.getText().length()==0)
					{
					label_11.setText("7-12位");
					}
			}
			public void focusLost(final FocusEvent e) {
					label_11.setText("");
			}
		});
		telField.setBounds(69, 140, 143, 21);
		frame.getContentPane().add(telField);

		final JLabel label_5 = new JLabel();
		label_5.setText("E_mail:");
		label_5.setBounds(21, 167, 57, 16);
		frame.getContentPane().add(label_5);

		final JTextField emailField = new JTextField();
		emailField.setText(user[9].trim());
		emailField.setBounds(69, 166, 143, 21);
		frame.getContentPane().add(emailField);

		final JLabel label_6 = new JLabel();
		label_6.setText("入职日期:");
		label_6.setBounds(8, 193, 65, 16);
		frame.getContentPane().add(label_6);

		final JTextField timeField = new JTextField();
		String time=user[7];
		timeField.setText(time.substring(0,10));
		timeField.setEditable(false);
		timeField.setBounds(69, 192, 143, 21);
		frame.getContentPane().add(timeField);

		final JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBorder(BorderFactory.createTitledBorder("个人备注(30字之内)"));
		scrollPane.setBounds(8, 249, 253, 101);
		frame.getContentPane().add(scrollPane);

		final JTextArea textArea = new JTextArea();
		textArea.setText(user[12].trim());
		textArea.setLineWrap(true);
		scrollPane.setViewportView(textArea);

		final JButton head = new JButton();
		head.setIcon(SwingResourceManager.getIcon(ShowUserInfoGUI.class, user[11]));
		head.setBounds(266, 6, 44, 42);
		frame.getContentPane().add(head);

		if(user[5].equals("男"))
		{
			men.setSelected(true);
			sex="男";
		}
		else
		{
			women.setSelected(true);
			sex="女";
		}
		final JButton updateBtn = new JButton();
		updateBtn.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				if(nameField.getText().length()==0)
				{
					JOptionPane.showMessageDialog(frame,"姓名不能为空!","警告",JOptionPane.WARNING_MESSAGE,null);
					return;
				}else
				{
					if(!(Check.checkMsg(nameField.getText(),2,4,false)))
					{
						JOptionPane.showMessageDialog(frame,"姓名长度不在范围之内,请保持输入在2-4之内!","警告",JOptionPane.WARNING_MESSAGE,null);
						nameField.setText("");
		 				return;
					}
				}
				if(sex.equals(""))
				{
					JOptionPane.showMessageDialog(frame,"请选择性别!","警告",JOptionPane.WARNING_MESSAGE,null);
					return;
				}
				if((!(Check.checkMsg(telField.getText(), 7, 12, true)))||telField.getText().length()==0)
				{
					JOptionPane.showMessageDialog(frame,"电话输入的不对,请确认是在7-12的数字!","警告",JOptionPane.WARNING_MESSAGE,null);
					return;
				}
				if((!(Check.includeChar(emailField.getText(),'@')))||emailField.getText().length()==0)
				{
					JOptionPane.showMessageDialog(frame,"E_mail输入的格式不正确!","警告",JOptionPane.WARNING_MESSAGE,null);
					return;
				}
				if(!(Check.checkMsg(textArea.getText(), 0, 30, false)))
				{
					JOptionPane.showMessageDialog(frame,"备注超过长度!","警告",JOptionPane.WARNING_MESSAGE,null);
					return;
				}
				try {
					ToServerProcess.oos.writeObject("更新个人信息:"+textField.getText()+":"+nameField.getText()+":"+telField.getText()+":"+emailField.getText()+":"+textArea.getText()+":"+headpic+":"+sex);
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				MainGUI.butpic.setIcon(SwingResourceManager.getIcon(ShowUserInfoGUI.class, headpic));
				MainGUI.label.setText("登录者:"+nameField.getText().trim());
			}
		});
		updateBtn.setText("修改");
		updateBtn.setBounds(130, 356, 70, 25);
		frame.getContentPane().add(updateBtn);

		final JButton button_2 = new JButton();
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				frame.dispose();
			}
		});
		button_2.setText("关闭");
		button_2.setBounds(204, 356, 67, 25);
		frame.getContentPane().add(button_2);

		final JButton ChangeHead = new JButton();
		ChangeHead.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				panel.setVisible(true);
			}
		});
		ChangeHead.addMouseListener(new MouseAdapter() {
			public void mouseEntered(final MouseEvent e) {
				ChangeHead.setIcon(SwingResourceManager.getIcon(ShowUserInfoGUI.class, "/edu/sccp/chat/image/0.gif"));
			}
			public void mouseExited(final MouseEvent e) {
				ChangeHead.setIcon(SwingResourceManager.getIcon(ShowUserInfoGUI.class, "/edu/sccp/chat/image/h7.gif"));
			}
		});
		ChangeHead.setIcon(SwingResourceManager.getIcon(ShowUserInfoGUI.class, "/edu/sccp/chat/image/h7.gif"));
		ChangeHead.setBounds(309, 23, 12, 25);
		frame.getContentPane().add(ChangeHead);
		
		panel = new JPanel();
		panel.setLayout(new GridLayout(0, 1));
		panel.setBounds(276, 47, 45, 318);
		panel.setVisible(false);
		frame.getContentPane().add(panel);

		final JButton button_4 = new JButton();
		button_4.setIcon(SwingResourceManager.getIcon(ShowUserInfoGUI.class, "/edu/sccp/chat/image/t1.png"));
		button_4.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				head.setIcon(button_4.getIcon());
				panel.setVisible(false);
				headpic="/edu/sccp/chat/image/t1.png";
			}
		});
		panel.add(button_4);

		final JButton button_5 = new JButton();
		button_5.setIcon(SwingResourceManager.getIcon(ShowUserInfoGUI.class, "/edu/sccp/chat/image/t2.png"));
		button_5.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				head.setIcon(button_5.getIcon());
				panel.setVisible(false);
				headpic="/edu/sccp/chat/image/t2.png";
			}
		});
		panel.add(button_5);

		final JButton button_6 = new JButton();
		button_6.setIcon(SwingResourceManager.getIcon(ShowUserInfoGUI.class, "/edu/sccp/chat/image/t3.png"));
		button_6.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				head.setIcon(button_6.getIcon());
				panel.setVisible(false);
				headpic="/edu/sccp/chat/image/t3.png";
			}
		});
		panel.add(button_6);

		final JButton button_7 = new JButton();
		button_7.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				head.setIcon(button_7.getIcon());
				panel.setVisible(false);
				headpic="/edu/sccp/chat/image/t7.png";
			}
		});
		button_7.setIcon(SwingResourceManager.getIcon(UpdateSelfUser.class, "/edu/sccp/chat/image/t7.png"));
		panel.add(button_7);

		final JButton button_8 = new JButton();
		button_8.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				head.setIcon(button_8.getIcon());
				panel.setVisible(false);
				headpic="/edu/sccp/chat/image/t4.png";
			}
		});
		button_8.setIcon(SwingResourceManager.getIcon(UpdateSelfUser.class, "/edu/sccp/chat/image/t4.png"));
		panel.add(button_8);

		final JButton button_9 = new JButton();
		button_9.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				head.setIcon(button_9.getIcon());
				panel.setVisible(false);
				headpic="/edu/sccp/chat/image/t5.png";
			}
		});
		button_9.setIcon(SwingResourceManager.getIcon(UpdateSelfUser.class, "/edu/sccp/chat/image/t5.png"));
		panel.add(button_9);

		final JButton button_10 = new JButton();
		button_10.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				head.setIcon(button_10.getIcon());
				panel.setVisible(false);
				headpic="/edu/sccp/chat/image/t6.png";
			}
		});
		button_10.setIcon(SwingResourceManager.getIcon(UpdateSelfUser.class, "/edu/sccp/chat/image/t6.png"));
		panel.add(button_10);

		final JButton button_11 = new JButton();
		button_11.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				head.setIcon(button_11.getIcon());
				panel.setVisible(false);
				headpic="/edu/sccp/chat/image/t8.png";
			}
		});
		button_11.setIcon(SwingResourceManager.getIcon(UpdateSelfUser.class, "/edu/sccp/chat/image/t8.png"));
		panel.add(button_11);
			nameField.setEditable(true);
			telField.setEditable(true);
			emailField.setEditable(true);
			textArea.setEditable(true);
			ChangeHead.setEnabled(true);
			updateBtn.setEnabled(true);

		final JLabel label_9 = new JLabel();
		label_9.setText("职务:");
		label_9.setBounds(21, 120, 43, 15);
		frame.getContentPane().add(label_9);

		final JTextField textField_1 = new JTextField();
		textField_1.setText(user[3].trim());
		textField_1.setEditable(false);
		textField_1.setBounds(69, 115, 88, 20);
		frame.getContentPane().add(textField_1);

		label_10 = new JLabel();
		label_10.setForeground(new Color(255, 0, 0));
		label_10.setBounds(211, 59, 60, 15);
		frame.getContentPane().add(label_10);

		label_11 = new JLabel();
		label_11.setForeground(new Color(255, 0, 0));
		label_11.setBounds(211, 142, 60, 15);
		frame.getContentPane().add(label_11);

		label_7 = new JLabel();
		label_7.setText("出生日期:");
		label_7.setBounds(8, 227, 57, 16);
		frame.getContentPane().add(label_7);

		textField_3 = new JTextField();
		String time1=user[6];
		textField_3.setText(time1.substring(0,10));
		textField_3.setBounds(69, 225, 143, 21);
		frame.getContentPane().add(textField_3);
	}
	public void showGUI()
	{
		frame.setResizable(false);
		frame.setSize(337,423);
		frame.setLocationRelativeTo(null);
		frame.setVisible(true);
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		//new UpdateSelfUser().showGUI();
	}


}

⌨️ 快捷键说明

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