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

📄 midclient.java

📁 基于TCP/IP的远程控制访问程序 可以对远程的计算机惊醒控制管理!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
import java.io.*;
import java.awt.Choice;
import java.awt.Dialog;
import java.awt.FlowLayout;
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.Color;
import java.net.Socket;
import java.net.InetAddress;
import javax.swing.*;
import java.awt.event.ActionListener;
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;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeNode;
import java.awt.Image;
import javax.swing.ImageIcon;
import java.awt.Toolkit;
public class midClient
{
    public static void main(String[] args) throws IOException
    {
        try{
        	  UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
           }
        catch(Exception e1){}
        new Ctree();
    }
}

class Ctree extends JFrame implements ActionListener
 {
    boolean disConnect=false;
    boolean passOk=true;
 	boolean startPort=false;
 	boolean DialogApp=false;
 	boolean  existFile;
 	FileOutputStream fo;
 	//*************************************1
 	JMenuBar menu=new JMenuBar();
 	JMenu    mnuFile =new JMenu("文件");
	JMenuItem AddComputer  =new JMenuItem("添加新主机");
	JMenuItem mnuFileExit  =new JMenuItem("退出");
	//*************************************2
	JButton Addcomputer=new JButton("隐藏主机");
	JLabel Host=new JLabel("选择主机");
	JPanel H_A=new JPanel();
	Choice Address=new Choice();
	JLabel ConnectIp=new JLabel(" 服务器IP地址 ");
 	JTextField ConnectIpText=new JTextField(14);
 	//*************************************3
 	DefaultMutableTreeNode Root = new DefaultMutableTreeNode("远程控制管理器");
	JTree tree = new JTree(Root);;
    JPopupMenu popM=new JPopupMenu();
    JMenuItem   cy_load=new JMenuItem("下载");
    JMenuItem   cy_delect=new JMenuItem("删除");
    JMenuItem   cy_refurbish=new JMenuItem("刷新子项");    
    JFileChooser Jsave=new JFileChooser();
    JScrollPane treePane=new JScrollPane();
    DefaultTreeCellRenderer cellRenderer=null;
    DefaultMutableTreeNode node1=null;
    DefaultTreeModel treeModel;
    File selectFile;
	//*************************************4
    Socket ClientSocket=null; //声名一个套接字
 	String  HostName=null;
 	int IPPort=0;
    PrintWriter out=null;
 	BufferedReader in=null;

	//子窗口按钮
	Dialog AddHost=null;
	JTextField Computer=null;
	JTextField Port1=null;
    JButton ok=new JButton("确定");
  	JButton cancel=new JButton("取消");

    Dialog listen      =null;
    JPasswordField passw   =new JPasswordField(10);
    JButton ok1        =new JButton("确认");
    JButton cancel1    =new JButton("取消");

 	File inputFile =new File("d:/");
	File[] list=inputFile.listRoots();
	int Jrate=0;
	int finish=0;
    int ByteNum;	
    String fileName;
    boolean copy=false;
	
	public  Ctree()
	 {
	    this("远程管理器");
	 }
	public Ctree(String Title)
	 {
	 	super(Title);
     	Image titlephone=Toolkit.getDefaultToolkit().createImage("./icons/client.gif");
     	this.setIconImage(titlephone);	 	
        this.setSize(600,500);
	    this.setJMenuBar(menu);
        tree.setShowsRootHandles(true);
        setFont(); 
 	    addWindows();
        //  tree.setEditable(false);
          ConnectIpText.setEditable(false);

          addListen();
	    try
	     {
	     	File AdressFile=new File("HostAddress.txt");
            if(!AdressFile.exists())
             {
             	AdressFile.createNewFile();
             }	
 	 	    FileReader readIn=new FileReader(AdressFile);
 	 	    BufferedReader bufin=new BufferedReader(readIn);
 	 	    String choiceList=null;
 	        String address,port;
 	 	    while((choiceList=bufin.readLine())!=null)
 	 	     {
 	 	     	 Root.add(new DefaultMutableTreeNode(choiceList));
 	 	         Address.add(choiceList);
 	 	     }
 	 	    bufin.close();
 	 	    readIn.close();
 	 	    this.setVisible(true);
 	 	  }
 	 	 catch(Exception E){}
     }
//******************************设置字体
    public void setFont()
     {  	
     	mnuFile.setFont(new Font("宋体",Font.PLAIN,12));
     	AddComputer.setFont(new Font("宋体",Font.PLAIN,12));
     	mnuFileExit.setFont(new Font("宋体",Font.PLAIN,12));
     	//2
     	Addcomputer.setFont(new Font("宋体",Font.PLAIN,13));
     	Host.setFont(new Font("宋体",Font.PLAIN,13));
     	Address.setFont(new Font("宋体",Font.PLAIN,13));
     	ConnectIp.setFont(new Font("宋体",Font.PLAIN,13));
     	ConnectIpText.setFont(new Font("宋体",Font.PLAIN,13));
     	//pop
        cy_load.setFont(new Font("宋体",Font.PLAIN,12));
        cy_delect.setFont(new Font("宋体",Font.PLAIN,12));
        cy_refurbish.setFont(new Font("宋体",Font.PLAIN,12));
     }	     
//******************************加入窗口容器    
	public void addWindows()
	  {
	    mnuFile.add(AddComputer);
	    mnuFile.addSeparator();
	    mnuFile.add(mnuFileExit);
	    menu.add(mnuFile);
	    H_A.add(Addcomputer);
	 	H_A.add(Host);
	 	H_A.add(Address);
	 	H_A.add(ConnectIp);
	 	H_A.add(ConnectIpText);
	 	tree.setRowHeight(21);
        tree.setCellRenderer(new EnhancedTreeCellRenderer());
        cellRenderer = (DefaultTreeCellRenderer)tree.getCellRenderer();

        cellRenderer.setFont(new Font("宋体",Font.PLAIN,14));
        cellRenderer.setBackgroundNonSelectionColor(Color.white);
        cellRenderer.setBackgroundSelectionColor(Color.blue);
        cellRenderer.setBorderSelectionColor(Color.yellow);
        cellRenderer.setTextNonSelectionColor(Color.black);
        cellRenderer.setTextSelectionColor(Color.white);       
 	    getContentPane().add(new JScrollPane(tree),BorderLayout.CENTER);
	    popM.add(cy_load);
	    popM.add(cy_delect);
        popM.addSeparator();	    
	    popM.add(cy_refurbish); 	    
	    tree.add(popM);
	    //*****************
          getContentPane().add(H_A,BorderLayout.NORTH);
      }
        //****************************监听信息
     public void addListen()
      {
          AddComputer.addActionListener(this);
          mnuFileExit.addActionListener(this);

          Addcomputer.addActionListener(this);

 	 	  //pop
 	 	  cy_refurbish.addActionListener(this);
 	 	  cy_load.addActionListener(this);
 	 	  cy_delect.addActionListener(this);
 	 	  tree.addMouseListener(new HandleMouse(this));
 	 	  this.addWindowListener(new WinAdptClient(this));

          //AddHost中的Button监听
          ok.addActionListener(this);
          cancel.addActionListener(this);
          //listen中的Button监听
          ok1.addActionListener(this);
          cancel1.addActionListener(this);
      }
/**********************************监听事件代码******************************/
  public void actionPerformed(ActionEvent e)
   {
   	 if(e.getSource()==AddComputer)
   	   {
   	   	  dialog();
   	   }
   	  else if(e.getSource()==Addcomputer)
   	   {
 	 	  if(this.startPort)
 	 	   { 
 	 	     if(e.getActionCommand()=="隐藏主机")
 	 	      {
 	 	         out.println("hideServer");
 	 	         out.flush();
 	 	         Addcomputer.setActionCommand("显示主机");
 	 	         Addcomputer.setName("显示主机");
 	 	         Addcomputer.updateUI();
 	 	      }
 	 	     else 
 	 	      {
 	 	      	out.println("appearServer");
 	 	      	out.flush();
 	 	      	Addcomputer.setActionCommand("隐藏主机");
 	 	      	Addcomputer.setName("隐藏主机");
 	 	      	Addcomputer.updateUI();
 	 	      }	    
 	 	   }     	       
   	   }
   	  else if(e.getSource()==mnuFileExit)
   	   {
   	   	  saveInit();
   	   	  quit();
   	   	  this.dispose();
   	   	  System.exit(0);
   	   }
   	  else if(e.getSource()==cy_refurbish)
   	   {
   	   	  update();
   	   }	 
   	  else if(e.getSource()==cy_load)
   	   {//要把文件路径给传过去
         connectThread star=new connectThread(this);
         star.start();
   	   }
   	  else if(e.getSource()==cy_delect)
   	  {
   	   	 try
   	   	  {
            int parameter=JOptionPane.showConfirmDialog(null,
               "是否删除文件 "+String.valueOf(tree.getSelectionPath()),"删除["+HostName+"]",JOptionPane.YES_NO_OPTION);  
           if(parameter==0)
             {     	   	  	
   	   	          String str=String.valueOf(tree.getSelectionPath());
   	   	          out.println("&delect&");
   	   	          out.flush();
   	        //	   System.out.println(str);
   	   	          out.println(str);
   	   	          out.flush();
   	   	          str=in.readLine();
   	   	          if(str.equals("1"))
   	   	           {
   	   	            	treeModel = (DefaultTreeModel)tree.getModel();
   	   	     	       TreePath treepath = tree.getSelectionPath();
             	       if (treepath != null)
             	        {
                	       DefaultMutableTreeNode selectionNode = (DefaultMutableTreeNode)
                           treepath.getLastPathComponent();
                 	       TreeNode parent = (TreeNode)selectionNode.getParent();
                 	       if (parent != null)
                	        {
                    	        treeModel.removeNodeFromParent(selectionNode);
                           //	 treeModel.reload();
                	        }
            	        }
                   }
              }     
   	      }
   	     catch(IOException E)
   	      {}
   	   }
   	  else if(e.getSource()==ok1)
   	   {
          listen.dispose();
   	   }
   	  else if(e.getSource()==cancel1)
   	   {
          passOk=false;
          HostName=null;
          passw.setText("");
          out.println("&exit&");
          out.flush();   	   	
          listen.dispose();
         // quit();
   	   }
   	  else if(e.getSource()==ok)
   	   {
          addchoice();
   	   }
   	  else if(e.getSource()==cancel)
   	   {
   	   	  AddHost.dispose();
   	   }
   }

/**********************修改端口***********************/
public void dialog()
  {
  	AddHost=new Dialog(this,"添加远程主机",true);
  	AddHost.addWindowListener
		  (
        	new WindowAdapter()
        	     {
			      public void windowClosing(WindowEvent e)
			        {
				      AddHost.dispose();
			        }
		         }
		   );
  	JPanel p1=new JPanel(new BorderLayout());
  	JPanel p2=new JPanel(new FlowLayout());
  	JPanel p11=new JPanel();
  	JPanel p12=new JPanel();
//  	Panel p13=new Panel(new FlowLayout());
  	JLabel label1=new JLabel("主机 : ");
  	Computer=new JTextField(12);
  	JLabel label2=new JLabel("端口 : ");  	
  	Port1=new JTextField(12);
//  	JLabel label3=new JLabel("密码 : ");
//  	JPasswordField mima=new JPasswordField(13);
    Computer.addKeyListener(new KeyLis(this,2));
    Port1.addKeyListener(new KeyLis(this,2));
  	label1.setFont(new Font("宋体",Font.PLAIN,12));
  	Computer.setFont(new Font("宋体",Font.PLAIN,12));  	
  	label2.setFont(new Font("宋体",Font.PLAIN,12));  	
  	Port1.setFont(new Font("宋体",Font.PLAIN,12));
    ok.setFont(new Font("宋体",Font.PLAIN,12)); 
  	cancel.setFont(new Font("宋体",Font.PLAIN,12));      
  	p2.add(ok);
  	p2.add(cancel);
  	p11.add(label1);
  	p11.add(Computer);
  	p12.add(label2);
  	p12.add(Port1);
//  	p13.add(label3);
//  	p13.add(mima);

⌨️ 快捷键说明

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