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

📄 midserver.java

📁 基于TCP/IP的远程控制访问程序 可以对远程的计算机惊醒控制管理!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
import java.io.File;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.FileReader;
import java.io.IOException;
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.InetAddress;
import java.awt.*;
import java.util.StringTokenizer;
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
public class midServer
 {
 	public static void main(String args[])
 	 {
 	    new SerWin();
 	 }
 }

 class SerWin extends JFrame implements ActionListener,ItemListener
  {
  	boolean serverBreak=false;
    File serverFile;
  	JPanel SWindow=new JPanel(new BorderLayout());
 	JPanel Ser1  =new JPanel(new BorderLayout());
 	JLabel Server=new JLabel("JAVA服务器");  //1

 	JPanel State =new JPanel();
 	JLabel      StateText  =new JLabel("服务器状态 :");
 	JTextField  ServerState=new JTextField(23);
 	JLabel      receiveText=new JLabel("接收 :");
 	JTextField  receive    =new JTextField(14);//2

 	JPanel Inform=new JPanel();
 	JLabel  InfoText   =new JLabel("服务器信息 :");
 	JTextField  ServerInfor =new JTextField(23);
 	JLabel  SendText   =new  JLabel("发送 :");
 	JTextField  Send	   =new JTextField(14);//3

 	JPanel Ser2=new JPanel(new GridBagLayout());
 	JPanel con        =new JPanel(new BorderLayout());
 	JPanel connectInfo=new JPanel();
 	JTextField connectClient=new JTextField("连接的客户机 :");
 	JTextField connectNum   =new JTextField(7);
 	JScrollPane editPane1   =new JScrollPane();
 	JTextArea  ClientInfo   =new JTextArea(10,15);//左容器4-5

 	JPanel ServerInfo       =new JPanel(new BorderLayout());
 	JPanel ServerD          =new JPanel();
    JTextField SerDialog    =new JTextField("服务器日志 :");
    JScrollPane editPane2   =new JScrollPane();
    JTextArea  SerInfo      =new JTextArea(10,23);//右容器4-5


    String[] ConnectComputer={"20","50","100","500","1000"};
    String[] cacheNum={"512","1024","2048","4096","8192"};
    JPanel Ser3=new JPanel(new BorderLayout());
    JPanel SetVar      =new JPanel(new BorderLayout());
    JPanel SetOne      =new JPanel();
    JLabel MaxNum  =new JLabel("最大连接数  :");
    Choice MaxConnect  =new Choice();
    JLabel ConnectText =new JLabel("计算机");
    JPanel SetTwo      =new JPanel();
    JLabel CacheNum    =new JLabel("缓冲区大小  :");
    Choice  Cache      =new Choice();
    JLabel  CacheText  =new JLabel("字节数");
    JPanel SetThree    =new JPanel(new BorderLayout());
    JLabel LisPort     =new JLabel("监听端口  :");
    JTextField Port    =new JTextField(3);
/////////////////////////////////////////////
    JPanel SetBut      =new JPanel(new BorderLayout());
    JButton ChangePort =new JButton(" 修改监听窗口 ");
     Dialog listen     =null;   
     JTextField portText  =new JTextField(8);     
     JCheckBox defaultPort=new JCheckBox("使用默认监听端口");
     JButton ok        =new JButton("确认");
     JButton cancel    =new JButton("取消"); 
/////////////////////////////////////////////////////     
    JButton ChangeKey  =new JButton("  修改密码   ");
     Dialog change     =null;
     JPasswordField old=new JPasswordField(10);
     JPasswordField nep=new JPasswordField(10);
     JPasswordField nea=new JPasswordField(10);
     JButton ok1       =new JButton("确认");
     JButton cancel1   =new JButton("取消");     
    JButton	ServerIp   =new JButton(" 主机定位系统 ");//右容器6-9
    //10
    JPanel CommulateBut=new JPanel(new FlowLayout());

    BufferedReader in=null;
    PrintWriter out=null;
    int count=0;
    boolean ClientOpen=false;
    ServerSocket m_sListener;
    Socket Connected;
    InetAddress C_Address;
    File passFile=null;    

    public SerWin()
     {
     	this("远程管理服务器");
     }
    public SerWin(String str)
     {
     	super(str);
     	Image titlephone=Toolkit.getDefaultToolkit().createImage("./icons/server.gif");
     	this.setIconImage(titlephone);     	
     	Container S_Window=getContentPane();
        S_Window.setLayout(new BorderLayout());
        ServerState.setText("正运行");
        Port.setText("8000");
        setFont();
        addContain();
        S_Window.add(SWindow,BorderLayout.NORTH);
     	S_Window.add(CommulateBut,BorderLayout.CENTER);
     	//设置为不可编辑
         setAttrib();
        //加入监听
        addListen();
     	//下拉菜单的加入
     	for(int i=0;i<5;i++)
     	 {
     	 	MaxConnect.add(ConnectComputer[i]);
     	 	Cache.add(cacheNum[i]);
     	 }
        this.setResizable(false);
     	pack();
 	 	this.setVisible(true);
 	    begin();
     }
   //**************************************************************************
  public void setFont()
     {
     	Server.setFont(new Font("宋体",Font.PLAIN,13));
     	StateText.setFont(new Font("宋体",Font.PLAIN,13));
     	ServerState.setFont(new Font("宋体",Font.PLAIN,13));
     	receiveText.setFont(new Font("宋体",Font.PLAIN,13));
     	receive.setFont(new Font("宋体",Font.PLAIN,13));
     	InfoText.setFont(new Font("宋体",Font.PLAIN,13));
     	ServerInfor.setFont(new Font("宋体",Font.PLAIN,13));
     	SendText.setFont(new Font("宋体",Font.PLAIN,13));
     	Send.setFont(new Font("宋体",Font.PLAIN,13));
     	//4-5
     	connectClient.setFont(new Font("宋体",Font.PLAIN,13));
     	connectNum.setFont(new Font("宋体",Font.PLAIN,13));
     	SerDialog.setFont(new Font("宋体",Font.PLAIN,13));
     	con.setFont(new Font("宋体",Font.PLAIN,13));
     	ServerInfo.setFont(new Font("宋体",Font.PLAIN,13));
     	//6-9
     	MaxNum.setFont(new Font("宋体",Font.PLAIN,13));
     	MaxConnect.setFont(new Font("宋体",Font.PLAIN,13));
     	ConnectText.setFont(new Font("宋体",Font.PLAIN,13));
     	CacheNum.setFont(new Font("宋体",Font.PLAIN,13));
     	LisPort.setFont(new Font("宋体",Font.PLAIN,13));
     	Cache.setFont(new Font("宋体",Font.PLAIN,13));
     	CacheText.setFont(new Font("宋体",Font.PLAIN,13));
     	
     	ChangePort.setFont(new Font("宋体",Font.PLAIN,13));
     	ChangeKey.setFont(new Font("宋体",Font.PLAIN,13));
     	ServerIp.setFont(new Font("宋体",Font.PLAIN,12));
     }	 
  public void addContain()
     {
     	  //加入1-3行字段
        State.add(StateText);    
        State.add(ServerState);
        State.add(receiveText);    
        State.add(receive);       
        Inform.add(InfoText);    
        Inform.add(ServerInfor);  
        Inform.add(SendText);
        Inform.add(Send);
     	Ser1.add(Server,BorderLayout.NORTH);
     	Ser1.add(State,BorderLayout.CENTER);
     	Ser1.add(Inform,BorderLayout.SOUTH);
        //4-5行字段
        //4-5左
        editPane1=new JScrollPane(ClientInfo);      
     	connectInfo.add(connectClient);
     	connectInfo.add(connectNum);
     	con.add(connectInfo,BorderLayout.NORTH);
     	con.add(editPane1,BorderLayout.CENTER);
        //4-5右
        editPane2=new JScrollPane(SerInfo); 
        ServerD.add(SerDialog);
     	ServerInfo.add(ServerD,BorderLayout.NORTH);
     	ServerInfo.add(editPane2,BorderLayout.CENTER);    	
     	Ser2.add(con);
     	Ser2.add(ServerInfo);
     	//6-9左
     	SetOne.add(MaxNum);
     	SetOne.add(MaxConnect);  	
     	SetOne.add(ConnectText);
     	SetTwo.add(CacheNum);
     	SetTwo.add(Cache);
     	SetTwo.add(CacheText);
     	SetThree.add(LisPort,BorderLayout.WEST);
     	SetThree.add(Port,BorderLayout.CENTER);
//     	SetThree.add(Startrun,BorderLayout.SOUTH);
     	SetVar.add(SetOne,BorderLayout.NORTH);
     	SetVar.add(SetTwo,BorderLayout.CENTER);
     	SetVar.add(SetThree,BorderLayout.SOUTH);
     	//6-9右
     	ChangePort.setIcon(new ImageIcon("./icons/port.gif"));
     	SetBut.add(ChangePort,BorderLayout.NORTH);
     	ChangeKey.setIcon(new ImageIcon("./icons/pass.gif"));
     	SetBut.add(ChangeKey,BorderLayout.CENTER);
     	ServerIp.setIcon(new ImageIcon("./icons/home.gif"));
     	SetBut.add(ServerIp,BorderLayout.SOUTH);

     	Ser3.add(SetVar,BorderLayout.WEST);
     	Ser3.add(SetBut,BorderLayout.CENTER);

     	SWindow.add(Ser1,BorderLayout.NORTH);
     	SWindow.add(Ser2,BorderLayout.CENTER);
     	SWindow.add(Ser3,BorderLayout.SOUTH);
     }
    public void setAttrib()
     {
     	ServerState.setEditable(false);
     	receive.setEditable(false);
     	Send.setEditable(false);
     	connectClient.setEditable(false);
     	connectNum.setEditable(false);
     	ClientInfo.setEditable(false);
     	ServerInfor.setEditable(false);
     	SerDialog.setEditable(false);
     	SerInfo.setEditable(false);

     	Port.setEditable(false);
     }	     //***********************************************************************
  public void addListen()
     {
     	this.addWindowListener(new WinAdpt(this));
        ChangePort.addActionListener(this);
        defaultPort.addItemListener(this);
        ok.addActionListener(this);
        cancel.addActionListener(this);
        ChangeKey.addActionListener(this);
        ok1.addActionListener(this);
        cancel1.addActionListener(this);
     }
 /*******************监听事件代码***********************/
  public void itemStateChanged(ItemEvent e)
   {
   	  if(e.getStateChange()==e.SELECTED)
   	   {
   	   	 this.portText.setText("7520");
   	   	 this.portText.setEditable(false);
   	   }
   	  else 
   	   {
   	   	  this.portText.setText(Port.getText());
   	   	  this.portText.setEditable(true);
   	   }	  	 
   }	
   
  public void actionPerformed(ActionEvent e)
     {
     	if(e.getSource()==ChangePort)
      	 {
      	 	CP_dialog();
      	 }
      	else if(e.getSource()==ok)
      	 {
      	 	listen.dispose();
      	 //	else
      	 	 {
      	 	/* 	Port.setText(portText.getText());
      	 	 	try
      	 	 	 {
      	 	 	 	m_sListener.close();
 	                if(ClientOpen)
 	                 {
 	     	           Connected.close();
 	     	           in.close();
 	     	           out.close();
 	                 }
 	                begin(); 
 	             }
 	            catch(IOException E){}*/     
 	         }      	       	 	
      	 }      
      	else if(e.getSource()==cancel)
      	 {
      	 	listen.dispose();
      	 }       	 	 
      	else if(e.getSource()==ChangeKey)
      	 {
      	 	old.setEditable(true);
      	 	CM_dialog();
      	 }	
      	else if(e.getSource()==ok1)
      	 {
      	   change.dispose();
           password();
      	 } 
      	else if(e.getSource()==cancel1)
      	 {
      	 	change.dispose();
      	 }       	       	 
     }

public void password()
 {
      	   if(passFile.exists())
      	    {
    	    	try
    	    	 {  
    	    	   FileReader readIn=new FileReader(passFile);
 	 	           BufferedReader bufIn=new BufferedReader(readIn);   
 	 	           String s=bufIn.readLine();
 	 	           if(!old.getText().equals(s)) 
 	 	            {
 	 	                JOptionPane.showMessageDialog(getContentPane(),
    	    	         "密码错误,请重输");     
    	    	        old.setText("");
    	    	        nea.setText("");
    	    	        nep.setText("");
 	 	                bufIn.close(); 
 	 	                readIn.close();     	    	            
    	    	        CM_dialog();	
 	 	            }
 	 	           else
 	 	            {
 	 	            	bufIn.close();
 	 	            	readIn.close();
 	 	            }	 
 	 	          }
 	 	        catch(IOException ee){}    	
 	 	    }         	    	
      	 	 if(nea.getText().length()>6&&nea.getText().equals(nep.getText()))
      	 	   {
      	 	   	 try
      	          { 
    	    	   FileWriter readOut=new FileWriter(passFile);
 	 	           BufferedWriter bufOut=new BufferedWriter(readOut);
 	 	           bufOut.write(nea.getText());
 	 	           bufOut.newLine();
 	 	           bufOut.flush();
 	 	           readOut.close();
 	 	 	       bufOut.close(); 
 	 	 	       old.setText("");
 	 	 	       nea.setText("");
 	 	 	       nep.setText("");	 
    	    	 JOptionPane.showMessageDialog(getContentPane(),
    	    	      "密码修改成功,请记住新密码");  	 	 	       	         	       	          	 	 	
      	 	      }    
      	 	     catch(IOException E){}   	 
      	 	   }     
    	    else
    	     {
    	    	 JOptionPane.showMessageDialog(getContentPane(),
    	    	      "密码不相同或者密码长度小于6,请重新输入");     
    	    	 old.setText("");
    	    	 nea.setText("");
    	    	 nep.setText("");     
    	    	 CM_dialog();     	    	    	       
    	     } 	
 }	     
public void CP_dialog()
  {
     JLabel ipPort        =new JLabel("端口"); 
     portText.setText(Port.getText());
  	 listen=new Dialog(this,"修改监听窗口",true);
  	 listen.addWindowListener
		  (
        	new WindowAdapter()
        	     {
			      public void windowClosing(WindowEvent e)
			        {
				      listen.dispose();
			        }
		         }
		   );
  	JPanel p1=new JPanel(new BorderLayout());
  	JPanel p11=new JPanel();
  	JPanel p12=new JPanel();
  	JPanel p2=new JPanel(new FlowLayout());
    p11.add(ipPort);
    p11.add(portText);
    p12.add(defaultPort);

⌨️ 快捷键说明

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