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

📄 logiongui.java

📁 企业级的即时通软件。。java语言写的 这是服务端部份。
💻 JAVA
字号:
package edu.sccp.chat.frame;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import com.swtdesigner.SwingResourceManager;


import edu.sccp.chat.bo.UserBO;
import edu.sccp.chat.jarClass.JarAllege;
import edu.sccp.chat.tools.Tools;

public class LogionGUI {

	private JTextField socketField;
	private JPasswordField passwordField;
	private JTextField nameField;
	private JLabel label_acc;
	private JLabel label_pwd;
	JLabel label_4;
	
	/**
	 * @param args
	 */
	JFrame frame;
	public LogionGUI()
	{
		JarAllege.bai();
		initGUI();
	}
	private void initGUI()
	{
		frame=new JFrame("企业即时通 登录");
		frame.setIconImage(SwingResourceManager.getImage(LogionGUI.class, "/edu/sccp/chat/image/zhuxiao.png"));
		frame.getContentPane().setLayout(null);

		final JLabel label = new JLabel();
		label.setFont(new Font("", Font.BOLD, 16));
		label.setText("服务器");
		label.setBounds(112, 12, 82, 33);
		frame.getContentPane().add(label);

		final JButton logion = new JButton();
		logion.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				if(Tools.isDigit(nameField.getText())){
					 if(!Tools.checkLength(nameField.getText(), 8, 10))
						 {
						 JOptionPane.showMessageDialog(frame, "用户名长度不符合,保持8-10位!", "提示", JOptionPane.INFORMATION_MESSAGE,null);
						 return;
						 }
				}else if(nameField.getText().equals(""))
				{
					JOptionPane.showMessageDialog(frame, "用户名不能为空!", "提示", JOptionPane.INFORMATION_MESSAGE,null);
					return;
				}	
				else
					{
					JOptionPane.showMessageDialog(frame, "用户名必须为数字!", "提示", JOptionPane.INFORMATION_MESSAGE,null);
					return;
					}
				if(passwordField.getPassword().toString()
						.equals(""))
					{
					JOptionPane.showMessageDialog(frame, "密码不能为空!", "提示", JOptionPane.INFORMATION_MESSAGE,null);
					return;
					}
				else if(!Tools.checkLength(passwordField.getPassword().toString(), 6, 10))
					{
					JOptionPane.showMessageDialog(frame, "密码长度不符合,保持在6-10位!", "提示", JOptionPane.INFORMATION_MESSAGE,null);
					return;
					}
				if(socketField.getText().length()!=0){
					if(!(Tools.isDigit(socketField.getText()) && Tools.inRange(socketField.getText(), 1024,65530))){
						{
							JOptionPane.showMessageDialog(frame, "端口号有误,保持在(1023-65530)!", "提示", JOptionPane.INFORMATION_MESSAGE,null);
							return;
						}
					}
				}
					String[] str=UserBO.logionSelect(nameField.getText().trim(),passwordField.getPassword());
					if(str[0].equals("T"))
					{
						frame.dispose();
						new MainGUI(nameField.getText().trim(),str[1].trim(),socketField.getText().trim()).showGUI();
					}else
					{
						JOptionPane.showMessageDialog(frame, "登录失败,用户名或密码错误!", "提示", JOptionPane.INFORMATION_MESSAGE,null);
						nameField.setText("");
						passwordField.setText("");
						return;
					}
				
			}
		});
		logion.setText("登录");
		logion.setBounds(20, 171, 70, 25);
		frame.getContentPane().add(logion);

		final JButton button_1 = new JButton();
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				nameField.setText("");
				passwordField.setText("");
			}
		});
		button_1.setText("重填");
		button_1.setBounds(108, 171, 71, 25);
		frame.getContentPane().add(button_1);

		final JButton close = new JButton();
		close.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				int i=JOptionPane.showConfirmDialog(frame,"确定要退出?","提示",JOptionPane.YES_OPTION,JOptionPane.INFORMATION_MESSAGE,null);
		 		if(i==0)
		 		{
		 			System.exit(0);
		 		}
			}
		});
		close.setText("退出");
		close.setBounds(197, 171, 71, 25);
		frame.getContentPane().add(close);

		final JTabbedPane tabbedPane = new JTabbedPane();
		tabbedPane.setBounds(10, 51, 272, 114);
		frame.getContentPane().add(tabbedPane);

		final JPanel panel = new JPanel();		
		panel.setLayout(null);
		tabbedPane.addTab("登录", null, panel, null);

		nameField = new JTextField();
		nameField.addFocusListener(new FocusAdapter() {
			public void focusGained(final FocusEvent e) {
				if(nameField.getText().length()==0)
				{
					label_acc.setText("8-10位");
				}else
					label_acc.setText("");
			}
			public void focusLost(final FocusEvent e) {
				if(nameField.getText().length()==0)
				{
					label_acc.setText("不能为空");
				}else
					label_acc.setText("");
			}
		});
		
		nameField.setBounds(67, 11, 132, 21);
		panel.add(nameField);

		final JLabel label_1 = new JLabel();
		label_1.setBounds(13, 12, 57, 16);
		panel.add(label_1);
		label_1.setText("用户名:");

		final JLabel label_2 = new JLabel();
		label_2.setBounds(14, 48, 57, 16);
		panel.add(label_2);
		label_2.setText("密码:");

		passwordField = new JPasswordField();
		passwordField.addFocusListener(new FocusAdapter() {
			public void focusGained(final FocusEvent e) {
				if(nameField.getText().length()==0)
				{
					label_pwd.setText("8-10位");
				}else
					label_pwd.setText("");
			}
			public void focusLost(final FocusEvent e) {
				if(nameField.getText().length()==0)
				{
					label_pwd.setText("不能为空");
				}else
					label_pwd.setText("");
			}
		});
		passwordField.setBounds(67, 45, 132, 23);
		panel.add(passwordField);

		label_acc = new JLabel();
		label_acc.setText(" ");
		label_acc.setBounds(203, 13, 62, 19);
		Tools.setFormat(label_acc);
		panel.add(label_acc);

		label_pwd = new JLabel();
		label_pwd.setText(" ");
		label_pwd.setBounds(203, 49, 62, 15);
		Tools.setFormat(label_pwd);
		panel.add(label_pwd);

		final JPanel panel_1 = new JPanel();
		panel_1.setLayout(null);
		tabbedPane.addTab("配置", null, panel_1, null);

		final JLabel label_3 = new JLabel();
		label_3.setText("端口号:");
		label_3.setBounds(29, 32, 57, 16);
		panel_1.add(label_3);

		socketField = new JTextField();
		socketField.addFocusListener(new FocusAdapter() {
			
			public void focusGained(final FocusEvent e) {
				if(socketField.getText().length()==0)
				label_4.setText("端口(1024-65530),默认5566");
				else
					label_4.setText("");
			}
		});
		socketField.setBounds(93, 31, 85, 21);
		panel_1.add(socketField);

		label_4 = new JLabel();
		label_4.setForeground(new Color(255, 0, 0));
		label_4.setBounds(74, 60, 183, 15);
		panel_1.add(label_4);
	}
	public void showGUI()
	{
		frame.setResizable(false);
		frame.setSize(300,235);
		frame.setLocationRelativeTo(null);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		new LogionGUI().showGUI();
	}

}

⌨️ 快捷键说明

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