




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
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.event.Action
2、Event;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.
3、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、0; UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); catch(Exception e1)
5、 new Ctree(); class Ctree extends JFrame implements ActionListener boolean disConnect=false; boolean passOk=true; boolean startPort=false; boolean Dia
6、logApp=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 JButton Addcomputer=new J
8、Button("隱藏主機(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、#160; JFileChooser Jsave=new JFileChooser(); JScrollPane treePane=new JScrollPane(); DefaultTreeCellRenderer cellRenderer=null; DefaultMutableTreeNode node1=null; DefaultTreeModel treeModel;
12、160; File selectFile; /*4 Socket ClientSocket=null; /聲名一個套接字 String HostName=null; int IPPort=0; PrintWriter out=null; Buffere
13、dReader in=null; /子窗口按鈕 Dialog AddHost=null; JTextField Computer=null; JTextField Port1=null; JButton ok=new JButton("確定")
14、; JButton cancel=new JButton("取消"); Dialog listen =null; JPasswordField passw =new JPasswordField(10); JButton ok1 =new J
15、Button("確認(rèn)"); JButton cancel1 =new JButton("取消"); File inputFile =new File("d:/"); File list=inputFile.listRoots(); int Jrate=
16、0; int finish=0; int ByteNum; String fileName; boolean copy=false; public Ctree()
17、160; this("遠(yuǎn)程管理器"); public Ctree(String Title) super(Title);
18、0; Image titlephone=Toolkit.getDefaultToolkit().createImage("./icons/client.gif"); this.setIconImage(titlephone);
19、 this.setSize(600,500); this.setJMenuBar(menu); tree.setShowsRootHandles(true); setFont(); addWindows();
20、160; / tree.setEditable(false); ConnectIpText.setEditable(false); addListen(); try &
21、#160; File AdressFile=new File("HostAddress.txt"); if(!AdressFile.exists()
22、160; AdressFile.createNewFile();
23、 FileReader readIn=new FileReader(AdressFile); BufferedReader bufin=new BufferedReader(readIn);
24、160; String choiceList=null; String address,port; while(choiceList=bufin.readLine()!=null)
25、160; Root.add(new DefaultMutableTreeNode(choiceList);
26、 Address.add(choiceList); bufin.close(); readIn
27、.close(); this.setVisible(true); catch(Exception E) /*設(shè)置字體
28、160; public void setFont() mnuFile.setFont(new Font("宋體",Font.PLAIN,12); AddComputer.setFont(new Font("宋體&q
29、uot;,Font.PLAIN,12); mnuFileExit.setFont(new Font("宋體",Font.PLAIN,12); /2 Addcomputer.setFont(new Font("宋體",Font.PLAIN,13);
30、0; Host.setFont(new Font("宋體",Font.PLAIN,13); Address.setFont(new Font("宋體",Font.PLAIN,13); ConnectIp.setFont(new Font("宋體",Font.PLAIN,
31、13); ConnectIpText.setFont(new Font("宋體",Font.PLAIN,13); /pop cy_load.setFont(new Font("宋體",Font.PLAIN,12);
32、60; cy_delect.setFont(new Font("宋體",Font.PLAIN,12); cy_refurbish.setFont(new Font("宋體",Font.PLAIN,12); /*加入窗口容器
33、 public void addWindows() mnuFile.add(AddComputer); mnuFile.addSeparator(); mnuFile.add(mnu
34、FileExit); menu.add(mnuFile); H_A.add(Addcomputer); H_A.add(Host);
35、160; H_A.add(Address); H_A.add(ConnectIp); H_A.add(ConnectIpText); tree.setRowHeight(21);
36、0; tree.setCellRenderer(new EnhancedTreeCellRenderer(); cellRenderer = (DefaultTreeCellRenderer)tree.getCellRenderer(); cellRenderer.setFont(new Font("宋體",Font.PLAI
37、N,14); cellRenderer.setBackgroundNonSelectionColor(Color.white); cellRenderer.setBackgroundSelectionColor(Color.blue); cellRenderer.setBorderSelectionColor(Color.yellow);
38、0; cellRenderer.setTextNonSelectionColor(Color.black); cellRenderer.setTextSelectionColor(Color.white); getContentPane().add(new JScrollP
39、ane(tree),BorderLayout.CENTER); popM.add(cy_load); popM.add(cy_delect); popM.addSeparator(); &
40、#160; popM.add(cy_refurbish); tree.add(popM); /* getCon
41、tentPane().add(H_A,BorderLayout.NORTH); /*監(jiān)聽信息 public void addListen() AddComputer.addActionListener(this);
42、; mnuFileExit.addActionListener(this); Addcomputer.addActionListener(this); /pop &
43、#160; cy_refurbish.addActionListener(this); cy_load.addActionListener(this); cy_delect.addActionListener(this);
44、60; tree.addMouseListener(new HandleMouse(this); this.addWindowListener(new WinAdptClient(this); /AddHost中的Button監(jiān)聽
45、160; ok.addActionListener(this); cancel.addActionListener(this); /listen中的Button監(jiān)聽 ok1.addActionListener(this);
46、60; cancel1.addActionListener(this); /*監(jiān)聽事件代碼*/ public void actionPerformed(ActionEvent e) if(e.getSource()=AddComputer)
47、 dialog(); else if(e.getSource()=Addcomputer) if(this.startPort) &
48、#160; if(e.getActionCommand()="隱藏主機(jī)")
49、; out.println("hideServer"); out.flush();
50、0; Addcomputer.setActionCommand("顯示主機(jī)"); Addcomputer.setName("顯示主機(jī)");
51、60; Addcomputer.updateUI(); else
52、60; out.println("appearServer");
53、; out.flush(); Addcomputer.setActionCommand("隱藏主機(jī)");
54、60; Addcomputer.setName("隱藏主機(jī)"); Addcomputer.updateUI();
55、; else if(e.getSource()=mnuFileExit)
56、160; saveInit(); quit(); this.dispose(); System.exit(0);
57、 else if(e.getSource()=cy_refurbish) update(); else
58、if(e.getSource()=cy_load) /要把文件路徑給傳過去 connectThread star=new connectThread(this); star.start(); el
59、se if(e.getSource()=cy_delect) try int parameter=JOptionPane.showConfirmDialog(null,
60、; "是否刪除文件 "+String.valueOf(tree.getSelectionPath(),"刪除"+HostName+"",JOptionPane.YES_NO_OPTION); if(parameter=0)
61、60; String str=String.valueOf(tree.getSelectionPath();
62、 out.println("&delect&"); out.flush();
63、0; / System.out.println(str); out.println(str);
64、160; out.flush(); str=in.readLine(); if(str.equals("1")
65、60; treeModel = (DefaultTreeModel)tree.getModel();
66、; TreePath treepath = tree.getSelectionPath();
67、60; if (treepath != null)
68、60; DefaultMutableTreeNode selectionNode = (DefaultMutableTreeNode) treepath.getLastPathCo
69、mponent(); TreeNode parent = (TreeNode)selectionNode.getParent();
70、 if (parent != null) &
71、#160; treeModel.removeNodeFromParent(selectionNode); &
72、#160; / treeModel.reload(); &
73、#160;
74、0; catch(IOException E)
75、; else if(e.getSource()=ok1) listen.dispose(); else if(e.getSource()=cancel1)
76、; passOk=false; HostName=null; passw.setText(""); out.println(
77、"&exit&"); out.flush(); listen.dispose(); / quit();
78、; else if(e.getSource()=ok) addchoice(); else if(e.getSource()=cancel)
79、 AddHost.dispose(); /*修改端口*/public void dialog() AddHost=new Dialog(this,"添加遠(yuǎn)程主機(jī)",true); AddHost.addWindowLis
80、tener ( new WindowAdapter()
81、; public void windowClosing(WindowEvent e)
82、; AddHost.dispose(); &
83、#160;
84、60; ); JPanel p1=new JPanel(new BorderLayout(); JPanel p2=new JPanel(new FlowLayout(); JPanel p11=new JPanel(); JPanel p12=new JPanel();/
85、Panel p13=new Panel(new FlowLayout(); JLabel label1=new JLabel("主機(jī) : "); Computer=new JTextField(12); JLabel label2=new JLabel("端口 : ");
86、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.setF
87、ont(new Font("宋體",Font.PLAIN,12); Computer.setFont(new Font("宋體",Font.PLAIN,12); label2.setFont(new Font("宋體",Font.PLAIN,12); Port1.setFont(new Font("宋體"
88、,Font.PLAIN,12); ok.setFont(new Font("宋體",Font.PLAIN,12); cancel.setFont(new Font("宋體",Font.PLAIN,12); p2.add(ok); p2.add(cancel); p
89、11.add(label1); p11.add(Computer); p12.add(label2); p12.add(Port1);/ p13.add(label3);/ p13.add(mima); p1.add("North",p11); p1.add("Cen
90、ter",p12);/ p1.add("South",p13); AddHost.add("North",p1); AddHost.add("Center",p2); /AddHost.setBounds(200,150,400,130); AddHost.setSize(150,150);
91、 AddHost.show(); /服務(wù)器文件存儲。public void down() try int result;
92、 existFile=false; result=Jsave.showSaveDialog(treePane); if(result=Jsave.APPROVE_OP
93、TION) selectFile = Jsave.getSelectedFile();
94、160; /取得選擇的文件 fileName=String.valueOf(selectFile); if(sele
95、ctFile.exists() String message =
96、 "文件已經(jīng)存在,要覆蓋嗎?" Object saveButton = "OK","NO"
97、 JOptionPane save= new JOptionPane(message,JOptionPane.WARNING_MESSAGE, &
98、#160; JOptionPane.DEFAULT_OPTION,null,saveButton);
99、0; JDialog saveD = save.createDialog(save,"保存文件"); /產(chǎn)生 saveD 對話框 saveD.setVisible(true);
100、0; Object push = save.getValue(); if(push = saveButton0)
101、0;
102、160; existFile=true;
103、160; else
104、160; existFile=true;
105、160; if(existFile) File outputFi
106、le = new File(selectFile.getAbsolutePath(); fo=new FileOutputStream(outputFile);
107、160; String str=String.valueOf(tree.getSelectionPath(); System.out.println(str);
108、0; out.println("&download&"); out.flush(); &
109、#160; out.println(str); out.flush();
110、160; catch(IOException e)
111、0; BufferedInputStream bufin; public void connect() try
112、60; disConnect=false; ClientSocket=new Socket(HostName,IPPort); InetAddress HostAddress=ClientSocket.get
113、InetAddress(); ConnectIpText.setText(HostAddress.toString(); out=new PrintWriter(ClientSocket.getOutputStream(),true
114、); in=new BufferedReader(new InputStreamReader(ClientSocket.getInputStream(); bufin=new BufferedInputStream(Cl
115、ientSocket.getInputStream(); if(node1.getChildCount()>0) &
116、#160; out.println("&pass&"); out.flush(); &
117、#160; else
118、0; String s1=new String("&nopass&"); while(s1.equals("&nopass&")
119、0; CP_dialog();
120、160; if(passOk)
121、0; out.println(passw.getText(); out.flush();
122、 passw.setText(""); s1=in.readLine();
123、0; if(s1.equals("&nopass&")
124、; JOptionPane.showMessageDialog(getContentPane(), &
125、#160; "密碼錯誤,請重輸");
126、0; else
127、 disConnect=true; &
128、#160; out.close(); &
129、#160; in.close(); ClientSocket.close();
130、; JOptionPane.showMessageDialog(getContentPane(),
131、 "目前處于非連接狀態(tài),請點(diǎn)擊主機(jī)I重新建立連接"); break;
132、60;
133、160; if(!disConnect)
134、160; startPort=true; String s=in.readLine();
135、60; while(!s.equals("&&over&&")
136、60; node1.add(new DefaultMutableTreeNode(s);
137、60; s=in.readLine();
138、160; System.out.println("over");
139、; catch(Exception e) /密碼輸入窗口public void CP_dialog() passOk=true; JLabel host
140、160; =new JLabel("主機(jī)"); JTextField hostText =new JTextField(10); hostText.setEditable(false); JLabel ipPort =new JLabel("端口"); JTextFiel
141、d portText =new JTextField(10); portText.setEditable(false); JLabel pass =new JLabel("密碼"); hostText.setText(HostName); portText.setTe
142、xt(String.valueOf(IPPort); listen=new Dialog(this,"登陸服務(wù)器",true); listen.addWindowListener (
143、60; new WindowAdapter()
144、0; public void windowClosing(WindowEvent e) &
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年證件打印一體機(jī)項(xiàng)目合作計(jì)劃書
- 2025年中石化:石油腦項(xiàng)目合作計(jì)劃書
- 吧臺設(shè)備轉(zhuǎn)讓合同范例
- 影片拍攝投標(biāo)合同范本
- 農(nóng)業(yè)技能培訓(xùn)合同范本
- 司機(jī)水泥合同范例
- 合同范例新版正版
- 單位綠化施工合同范例
- LED戶外顯示屏廣告位租賃合同范本
- 個人購房合同范本簡易
- 2025年黑龍江旅游職業(yè)技術(shù)學(xué)院單招職業(yè)傾向性測試題庫完整
- 部編版《道德與法治》四年級下冊全冊教案
- 雷鋒精神生生不息-2025年學(xué)校3.5學(xué)雷鋒月主題活動方案
- 山東2025年山東大學(xué)輔導(dǎo)員招聘筆試歷年參考題庫附帶答案詳解
- 骨科管理制度
- 電動叉車培訓(xùn)課件
- 2025年山東化工職業(yè)學(xué)院高職單招職業(yè)技能測試近5年??及鎱⒖碱}庫含答案解析
- 健身行業(yè)會員權(quán)益保障及免責(zé)條款協(xié)議
- 脾破裂保守治療的護(hù)理
- (正式版)HG∕T 21633-2024 玻璃鋼管和管件選用規(guī)定
- “供應(yīng)商融資安排”會計(jì)列報、披露問題研究
評論
0/150
提交評論