package com.demo;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.List;
import java.awt.event.ActionEvent;
import javax.swing.JTextArea;

public class StartService extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;
	private static ServiceSoketServerListenerThread sssl=null;
	private JTextArea textArea;
	private JButton button_2;
	private JTextField textField_2;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					StartService frame = new StartService();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public StartService() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 410, 469);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblIp = new JLabel("ip");
		lblIp.setBounds(10, 62, 54, 15);
		contentPane.add(lblIp);
		
		JLabel label = new JLabel("端口");
		label.setBounds(213, 62, 54, 15);
		contentPane.add(label);
		
		textField = new JTextField();
		textField.setText("127.0.0.1");
		textField.setBounds(59, 59, 66, 21);
		contentPane.add(textField);
		textField.setColumns(10);
		
		textField_1 = new JTextField();
		textField_1.setText("8080");
		textField_1.setColumns(10);
		textField_1.setBounds(275, 59, 66, 21);
		contentPane.add(textField_1);
		
		JButton button = new JButton("开启服务");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {

				if (button.getText().equals("开启服务")) {
					sssl = new ServiceSoketServerListenerThread(Integer.valueOf(textField_1.getText()), textArea);
					sssl.start();
					button.setText("关闭服务");
				} else {
					sssl.stopService();
					button.setText("开启服务");
				}

			}
		});
		button.setBounds(88, 120, 166, 23);
		contentPane.add(button);
		
		textArea = new JTextArea();
		textArea.setBounds(31, 177, 317, 130);
		  JScrollPane scrollPane_1 = new JScrollPane();
	        scrollPane_1.setBounds(31, 177, 317, 130);
	        scrollPane_1.setViewportView(textArea);
	        contentPane.add(scrollPane_1);                
		contentPane.add(scrollPane_1);
		
		
		
		button_2 = new JButton("向所有客户端发消息");
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				List<User> socketlist = ServiceSoketServerListenerThread.getSocketlist();
				for (User user : socketlist) {
					try {
						user.getSocket().getOutputStream().write(("服务器:"+textField_2.getText()).getBytes());
					} catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				}
				/*for (Socket socket : socketList) {
					try {
						socket.getOutputStream().write(("服务器:"+textField_2.getText()).getBytes());
					} catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
					
					try {
						DataOutputStream dis=new DataOutputStream(socket.getOutputStream());
						dis.writeUTF("服务器:"+textField_2.getText());
					} catch (IOException e1) {
						socketList.remove(socket);
						System.out.println("对方退出了!我从List里面去掉了!");
						e1.printStackTrace();
					}
				}*/
			}
		});
		button_2.setBounds(59, 398, 174, 23);
		contentPane.add(button_2);
		
		textField_2 = new JTextField();
		textField_2.setBounds(59, 332, 208, 21);
		contentPane.add(textField_2);
		textField_2.setColumns(10);
	}
}
最近下载更多
qwertasdfgkwuejwjwjw  LV1 2024年6月27日
jxd2007kl  LV2 2023年11月29日
谢小饭_  LV8 2022年1月21日
9843637  LV9 2021年12月15日
tangjj7260  LV18 2021年12月10日
dfz12345  LV4 2021年12月8日
 LV2 2021年6月16日
miner22  LV9 2021年5月27日
chat511  LV3 2021年5月12日
15508061020  LV1 2020年9月3日
最近浏览更多
13133117021  LV5 2024年12月23日
124324343  LV1 2024年6月29日
qwertasdfgkwuejwjwjw  LV1 2024年6月27日
taoshen95  LV16 2024年6月18日
周鸣郝  LV2 2024年5月26日
微信网友_7004855557083136  LV1 2024年5月22日
zeng1206  LV7 2023年12月28日
jxd2007kl  LV2 2023年11月29日
jidea  LV2 2023年11月29日
阿布屋脊  LV7 2023年8月15日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友