基于Java的遠(yuǎn)程桌面監(jiān)控源代碼_第1頁
基于Java的遠(yuǎn)程桌面監(jiān)控源代碼_第2頁
基于Java的遠(yuǎn)程桌面監(jiān)控源代碼_第3頁
基于Java的遠(yuǎn)程桌面監(jiān)控源代碼_第4頁
基于Java的遠(yuǎn)程桌面監(jiān)控源代碼_第5頁
已閱讀5頁,還剩38頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、 基于Java的遠(yuǎn)程桌面監(jiān)控源代碼來源:熊哲的日志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 .Socket;import .InetAddress;import javax.swing.*;import java.awt.event.ActionListener;import java.awt.even

2、t.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.swi

3、ng.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  &#

4、160;              UIManager.setLookAndFeel(".sun.java.swing.plaf.windows.WindowsLookAndFeel");                   catch(Exception e1)  &

5、#160;     new Ctree();     class Ctree extends JFrame implements ActionListener     boolean disConnect=false;    boolean passOk=true;      boolean startPort=false;      boolea

6、n DialogApp=false;      boolean  existFile;      FileOutputStream fo;      /*1      JMenuBar menu=new JMenuBar();      JMenu    mnuFile =new JMenu("文件

7、");       JMenuItem AddComputer  =new JMenuItem("添加新主機(jī)");       JMenuItem mnuFileExit  =new JMenuItem("退出");       /*2       utton Addcomputer=ne

8、w utton("隱藏主機(jī)");       JLabel Host=new JLabel("選擇主機(jī)");       JPanel H_A=new JPanel();       Choice Address=new Choice();       JLabel ConnectIp=new JLabel("

9、; 服務(wù)器IP地址 ");      JTextField ConnectIpText=new JTextField(14);      /*3      DefaultMutableTreeNode Root = new DefaultMutableTreeNode("遠(yuǎn)程控制管理器");       JTree tree = new JTree(Root

10、);    JPopupMenu popM=new JPopupMenu();    JMenuItem   cy_load=new JMenuItem("下載");    JMenuItem   cy_delect=new JMenuItem("刪除");    JMenuItem   cy_refurbish=new JMenuItem("刷新子項(xiàng)");

11、       JFileChooser Jsave=new JFileChooser();    JScrollPane treePane=new JScrollPane();    DefaultTreeCellRenderer cellRenderer=null;    DefaultMutableTreeNode node1=null;    DefaultTreeModel treeModel; &

12、#160;  File selectFile;       /*4    Socket ClientSocket=null; /聲名一個(gè)套接字      String  HostName=null;      int IPPort=0;    PrintWriter out=null;      Buffer

13、edReader in=null;        /子窗口按鈕       Dialog AddHost=null;       JTextField Computer=null;       JTextField Port1=null;    utton ok=new utton("確定");&#

14、160;     utton cancel=new utton("取消");     Dialog listen      =null;    JPasswordField passw   =new JPasswordField(10);    utton ok1        =new utton(&quo

15、t;確認(rèn)");    utton cancel1    =new utton("取消");       File inputFile =new File("d:/");       File list=inputFile.listRoots();       int Jrate=0;  &

16、#160;    int finish=0;    int ByteNum;     String fileName;    boolean copy=false;        public  Ctree()                

17、0;  this("遠(yuǎn)程管理器");               public Ctree(String Title)                     super(Title);       

18、   Image titlephone=Toolkit.getDefaultToolkit().createImage("./icons/client.gif");          this.setIconImage(titlephone);                   this.setSize(6

19、00,500);           this.setJMenuBar(menu);        tree.setShowsRootHandles(true);        setFont();          addWindows();    

20、;    /  tree.setEditable(false);          ConnectIpText.setEditable(false);           addListen();           try    

21、0;                        File AdressFile=new File("HostAddress.txt");            if(!AdressFile.exists()      

22、;                         AdressFile.createNewFile();                        

23、60;       FileReader readIn=new FileReader(AdressFile);                BufferedReader bufin=new BufferedReader(readIn);                String cho

24、iceList=null;              String address,port;                while(choiceList=bufin.readLine()!=null)             

25、0;                          Root.add(new DefaultMutableTreeNode(choiceList);                     Address.

26、add(choiceList);                                 bufin.close();                readIn.close(); 

27、               this.setVisible(true);                           catch(Exception E)     /*設(shè)置字體   

28、; public void setFont()                       mnuFile.setFont(new Font("宋體",Font.PLAIN,12);          AddComputer.setFont(new Font("宋體",Font.PLAIN

29、,12);          mnuFileExit.setFont(new Font("宋體",Font.PLAIN,12);          /2          Addcomputer.setFont(new Font("宋體",Font.PLAIN,13);    

30、     Host.setFont(new Font("宋體",Font.PLAIN,13);          Address.setFont(new Font("宋體",Font.PLAIN,13);          ConnectIp.setFont(new Font("宋體",Font.PLAIN,13);  

31、;        ConnectIpText.setFont(new Font("宋體",Font.PLAIN,13);          /pop        cy_load.setFont(new Font("宋體",Font.PLAIN,12);        cy_de

32、lect.setFont(new Font("宋體",Font.PLAIN,12);        cy_refurbish.setFont(new Font("宋體",Font.PLAIN,12);             /*加入窗口容器          public void ad

33、dWindows()                    mnuFile.add(AddComputer);           mnuFile.addSeparator();           mnuFile.add(mnuFileExit); 

34、;          menu.add(mnuFile);           H_A.add(Addcomputer);             H_A.add(Host);             H_A.

35、add(Address);             H_A.add(ConnectIp);             H_A.add(ConnectIpText);             tree.setRowHeight(21);   

36、    tree.setCellRenderer(new EnhancedTreeCellRenderer();        cellRenderer = (DefaultTreeCellRenderer)tree.getCellRenderer();         cellRenderer.setFont(new Font("宋體",Font.PLAIN,14); 

37、60;      cellRenderer.setBackgroundNonSelectionColor(Color.white);        cellRenderer.setBackgroundSelectionColor(Color.blue);        cellRenderer.setBorderSelectionColor(Color.yellow);   &

38、#160;    cellRenderer.setTextNonSelectionColor(Color.black);        cellRenderer.setTextSelectionColor(Color.white);                getContentPane().add(new JScrollPane(tree),Borde

39、rLayout.CENTER);           popM.add(cy_load);           popM.add(cy_delect);        popM.addSeparator();            

40、0;     popM.add(cy_refurbish);                     tree.add(popM);           /*          getContentPane().add(

41、H_A,BorderLayout.NORTH);              /*監(jiān)聽信息     public void addListen()                AddComputer.addActionListener(this);    &#

42、160;     mnuFileExit.addActionListener(this);           Addcomputer.addActionListener(this);               /pop          

43、0;   cy_refurbish.addActionListener(this);              cy_load.addActionListener(this);              cy_delect.addActionListener(this);         

44、     tree.addMouseListener(new HandleMouse(this);              this.addWindowListener(new WinAdptClient(this);           /AddHost中的Button監(jiān)聽       

45、;   ok.addActionListener(this);          cancel.addActionListener(this);          /listen中的Button監(jiān)聽          ok1.addActionListener(this);   

46、       cancel1.addActionListener(this);      /*監(jiān)聽事件代碼*/  public void actionPerformed(ActionEvent e)         if(e.getSource()=AddComputer)               

47、60;    dialog();               else if(e.getSource()=Addcomputer)                      if(this.startPort)       

48、60;                        if(e.getActionCommand()="隱藏主機(jī)")                          &

49、#160;            out.println("hideServer");                     out.flush();              

50、       Addcomputer.setActionCommand("顯示主機(jī)");                     Addcomputer.setName("顯示主機(jī)");             

51、;        Addcomputer.updateUI();                                   else         

52、                               out.println("appearServer");                    &

53、#160; out.flush();                      Addcomputer.setActionCommand("隱藏主機(jī)");                      Addcomputer

54、.setName("隱藏主機(jī)");                      Addcomputer.updateUI();                          &#

55、160;                                           else if(e.getSource()=mnuFileExit)          

56、;          saveInit();            quit();            this.dispose();            System.exit(0);       

57、60;       else if(e.getSource()=cy_refurbish)                    update();                     else if(e.getSource(

58、)=cy_load)        /要把文件路徑給傳過去         connectThread star=new connectThread(this);         star.start();               else if(e.getSour

59、ce()=cy_delect)                  try                        int parameter=JOptionPane.showConfirmDialog(null,    &#

60、160;          "是否刪除文件 "+String.valueOf(tree.getSelectionPath(),"刪除"+HostName+"",JOptionPane.YES_NO_OPTION);            if(parameter=0)      

61、                                            String str=String.valueOf(tree.getSelectionPath();     &

62、#160;              out.println("&delect&");                    out.flush();           &

63、#160; /        System.out.println(str);                    out.println(str);                    

64、;out.flush();                    str=in.readLine();                    if(str.equals("1")       

65、;                                           treeModel = (DefaultTreeModel)tree.getModel();    

66、                      TreePath treepath = tree.getSelectionPath();                        

67、 if (treepath != null)                                                

68、        DefaultMutableTreeNode selectionNode = (DefaultMutableTreeNode)                           treepath.getLastPathComponent(); 

69、;                            TreeNode parent = (TreeNode)selectionNode.getParent();              

70、60;              if (parent != null)                                   

71、0;                              treeModel.removeNodeFromParent(selectionNode);             

72、0;             /       treeModel.reload();                             

73、0;                                                    &

74、#160;                                 catch(IOException E)                    &#

75、160;     else if(e.getSource()=ok1)                  listen.dispose();               else if(e.getSource()=cancel1)        &#

76、160;         passOk=false;          HostName=null;          passw.setText("");          out.println("&exit

77、&");          out.flush();                    listen.dispose();         / quit();        &#

78、160;      else if(e.getSource()=ok)                  addchoice();               else if(e.getSource()=cancel)        

79、60;           AddHost.dispose();            /*修改端口*/public void dialog()        AddHost=new Dialog(this,"添加遠(yuǎn)程主機(jī)",true);      AddHost.addWindowListener 

80、0;              (               new WindowAdapter()                      &#

81、160;                        public void windowClosing(WindowEvent e)                     &

82、#160;                                         AddHost.dispose();       

83、0;                                                     

84、        );      JPanel p1=new JPanel(new BorderLayout();      JPanel p2=new JPanel(new FlowLayout();      JPanel p11=new JPanel();      JPanel p12=new JPanel();/    Panel p13=new P

85、anel(new FlowLayout();      JLabel label1=new JLabel("主機(jī) : ");      Computer=new JTextField(12);      JLabel label2=new JLabel("端口 : ");              Port1=new JText

86、Field(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(&q

87、uot;宋體",Font.PLAIN,12);      Computer.setFont(new Font("宋體",Font.PLAIN,12);          label2.setFont(new Font("宋體",Font.PLAIN,12);         Port1.setFont(new Font("宋體",Font.PLAIN,12)

88、;    ok.setFont(new Font("宋體",Font.PLAIN,12);      cancel.setFont(new Font("宋體",Font.PLAIN,12);           p2.add(ok);      p2.add(cancel);      p11.add(label1);

89、      p11.add(Computer);      p12.add(label2);      p12.add(Port1);/    p13.add(label3);/    p13.add(mima);      p1.add("North",p11);      p1.add("Center",p12);

90、/    p1.add("South",p13);      AddHost.add("North",p1);      AddHost.add("Center",p2);      /AddHost.setBounds(200,150,400,130);      AddHost.setSize(150,150);    &#

91、160; AddHost.show();   /服務(wù)器文件存儲(chǔ)。public void down()       try                       int result;             

92、60;   existFile=false;                 result=Jsave.showSaveDialog(treePane);                 if(result=Jsave.APPROVE_OPTION) 

93、0;                                    selectFile = Jsave.getSelectedFile();           

94、;   /取得選擇的文件                    fileName=String.valueOf(selectFile);                    if(selectFile.exists()

95、                                                 String message = "文件已經(jīng)存在,要

96、覆蓋嗎?"                         Object saveButton = "OK","NO"                  

97、60;        JOptionPane save= new JOptionPane(message,JOptionPane.WARNING_MESSAGE,                              

98、0;                       JOptionPane.DEFAULT_OPTION,null,saveButton);                    &

99、#160;     JDialog saveD = save.createDialog(save,"保存文件");  /產(chǎn)生 saveD 對(duì)話框                       saveD.setVisible(true);      &

100、#160;                Object push = save.getValue();                       if(push = saveButton0)   &

101、#160;                                                   exis

102、tFile=true;                                                  

103、;                 else                                  

104、;              existFile=true;                                    

105、;   if(existFile)                                             File outputFile = new File(s

106、electFile.getAbsolutePath();                        fo=new FileOutputStream(outputFile);                  

107、;  String str=String.valueOf(tree.getSelectionPath();                      System.out.println(str);               &

108、#160;    out.println("&download&");                      out.flush();                   

109、0;   out.println(str);                      out.flush();                         

110、;                                        catch(IOException e)              

111、       BufferedInputStream bufin; public void connect()              try                            

112、 disConnect=false;                  ClientSocket=new Socket(HostName,IPPort);                  InetAddress HostAddress=ClientSocket.getInetAddress();&

113、#160;                 ConnectIpText.setText(HostAddress.toString();                  out=new PrintWriter(ClientSocket.getOutputStream(),true);  &

114、#160;               in=new  BufferedReader(new InputStreamReader(ClientSocket.getInputStream();                  bufin=new BufferedInputStream(ClientSocket.getI

115、nputStream();                  if(node1.getChildCount()>0)                               

116、60;           out.println("&pass&");                        out.flush();            

117、60;                    else                                     &

118、#160; String s1=new String("&nopass&");                        while(s1.equals("&nopass&")              

119、                                   CP_dialog();                   

120、;     if(passOk)                                                 

121、   out.println(passw.getText();                           out.flush();                 

122、60;         passw.setText("");                           s1=in.readLine();          

123、                if(s1.equals("&nopass&")                              &#

124、160;                          JOptionPane.showMessageDialog(getContentPane(),                   

125、0;             "密碼錯(cuò)誤,請(qǐng)重輸");                                     &

126、#160;                                         else             &#

127、160;                                             disConnect=true;      

128、0;                          out.close();                          

129、0;      in.close();                                 ClientSocket.close();           &

130、#160;                     JOptionPane.showMessageDialog(getContentPane(),                        

131、60;        "目前處于非連接狀態(tài),請(qǐng)點(diǎn)擊主機(jī)I重新建立連接");                              break;        

132、;                                                       

133、0;                 if(!disConnect)                                     

134、0;              startPort=true;                         String s=in.readLine();           

135、              while(!s.equals("&&over&&")                                  

136、;                         node1.add(new DefaultMutableTreeNode(s);                         

137、;       s=in.readLine();                                               

138、;    System.out.println("over");                                               &

139、#160;                catch(Exception e)  /密碼輸入窗口public void CP_dialog()         passOk=true;       JLabel host          =new JLabe

140、l("主機(jī)");     JTextField hostText  =new JTextField(10);     hostText.setEditable(false);     JLabel ipPort        =new JLabel("端口");     JTextField portText 

141、; =new JTextField(10);     portText.setEditable(false);     JLabel pass          =new JLabel("密碼");     hostText.setText(HostName);     portText.setText(String.value

142、Of(IPPort);       listen=new Dialog(this,"登陸服務(wù)器",true);       listen.addWindowListener                (            

143、   new WindowAdapter()                                               public

144、 void windowClosing(WindowEvent e)                                                       

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論