远程桌面监控系统java_基于Java的远程桌面监控源代码
《基于Java的遠程桌面監控源代碼》由會員分享,可在線閱讀,更多相關《基于Java的遠程桌面監控源代碼(43頁珍藏版)》請在人人文庫網上搜索。
1、基于Java的遠程桌面監控源代碼 來源: 熊哲的日志 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;im。
2、port 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.DefaultTreeMode。
3、l;import javax.swing.tree.TreePath;import javax.swing.tree.TreeNode;import java.awt.Image;import javax.swing.ImageIcon;import java.awt.Toolkit;public class midClientpublic static void main(String args) throws IOExceptiontryUIManager.setLookAndFeel(com.sun.java.swing.plaf.windows.WindowsLookAndFeel);。
4、catch(Exception e1)new Ctree();class Ctree extends JFrame implements ActionListenerboolean disConnect=false;boolean passOk=true;boolean startPort=false;boolean DialogApp=false;boolean existFile;FileOutputStream fo;/*1JMenuBar menu=new JMenuBar();JMenu mnuFile =new JMenu(文件);JMenuItem AddComputer =ne。
5、w JMenuItem(添加新主機);JMenuItem mnuFileExit =new JMenuItem(退出);/*2JButton 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);/*3DefaultMutableTreeNode Root = ne。
6、w 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();DefaultTre。
7、eCellRenderer cellRenderer=null;DefaultMutableTreeNode node1=null;DefaultTreeModel treeModel;File selectFile;/*4Socket ClientSocket=null; /聲名一個套接字String HostName=null;int IPPort=0;PrintWriter out=null;BufferedReader in=null;/子窗口按鈕Dialog AddHost=null;JTextField Computer=null;JTextField Port1=null;JBu。
8、tton 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;boo。
9、lean 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.setEd。
10、itable(false);ConnectIpText.setEditable(false);addListen();tryFile 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(choi。
11、ceList=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。
12、.setFont(new Font(宋體,Font.PLAIN,12);/2Addcomputer.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);/popcy_load.setFont(new Font(宋體,Font.P。
13、LAIN,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。
14、.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.setBackgroundSelectionCol。
15、or(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_。
16、refurbish); tree.add(popM);/*getContentPane().add(H_A,BorderLayout.NORTH);/*監聽信息public void addListen()AddComputer.addActionListener(this);mnuFileExit.addActionListener(this);Addcomputer.addActionListener(this);/popcy_refurbish.addActionListener(this);cy_load.addActionListener(this);cy_delect.addAct。
17、ionListener(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(。
18、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();elseout.println(appearServer);out.flush();Addco。
19、mputer.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。
20、();else if(e.getSource()=cy_delect)tryint 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);。
21、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)sel。
22、ectionNode.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();/ qui。
23、t();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();JP。
24、anel 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。
25、 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(宋體,Fon。
26、t.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);p1.add(North,p11);p1.add(Center,p12);/ p1.add(South,p13);AddHost.add(North,p1);AddHost.add(Center,p2);/AddHost.setBounds(。
27、200,150,400,130);AddHost.setSize(150,150);AddHost.show();/服務器文件存儲。public void down()tryint result;existFile=false;result=Jsave.showSaveDialog(treePane);if(result=Jsave.APPROVE_OPTION)selectFile = Jsave.getSelectedFile(); /取得選擇的文件fileName=String.valueOf(selectFile);if(selectFile.exists()String messag。
28、e = 文件已經存在,要覆蓋嗎?;Object saveButton = OK,NO;JOptionPane save= new JOptionPane(message,JOptionPane.WARNING_MESSAGE,JOptionPane.DEFAULT_OPTION,null,saveButton);JDialog saveD = save.createDialog(save,保存文件); /產生 saveD 對話框saveD.setVisible(true);Object push = save.getValue();if(push = saveButton0)existFile。
29、=true;elseexistFile=true;if(existFile)File outputFile = new File(selectFile.getAbsolutePath();fo=new FileOutputStream(outputFile);String str=String.valueOf(tree.getSelectionPath();System.out.println(str);out.println(&download&);out.flush();out.println(str);out.flush();catch(IOException e)BufferedInp。
30、utStream bufin;public void connect()trydisConnect=false;ClientSocket=new Socket(HostName,IPPort);InetAddress HostAddress=ClientSocket.getInetAddress();ConnectIpText.setText(HostAddress.toString();out=new PrintWriter(ClientSocket.getOutputStream(),true);in=new BufferedReader(new InputStreamReader(Cli。
31、entSocket.getInputStream();bufin=new BufferedInputStream(ClientSocket.getInputStream();if(node1.getChildCount()0)out.println(&pass&);out.flush();elseString s1=new String(&nopass&);while(s1.equals(&nopass&)CP_dialog();if(passOk)out.println(passw.getText();out.flush();passw.setText();s1=in.readLine();。
32、if(s1.equals(&nopass&)JOptionPane.showMessageDialog(getContentPane(),密碼錯誤,請重輸);elsedisConnect=true;out.close();in.close();ClientSocket.close();JOptionPane.showMessageDialog(getContentPane(),目前處于非連接狀態,請點擊主機I重新建立連接);break;if(!disConnect)startPort=true;String s=in.readLine();while(!s.equals(&over&)node。
33、1.add(new DefaultMutableTreeNode(s);s=in.readLine();System.out.println(over);catch(Exception e)/密碼輸入窗口public void CP_dialog()passOk=true;JLabel host =new JLabel(主機);JTextField hostText =new JTextField(10);hostText.setEditable(false);JLabel ipPort =new JLabel(端口);JTextField portText =new JTextField(1。
34、0);portText.setEditable(false);JLabel pass =new JLabel(密碼);hostText.setText(HostName);portText.setText(String.valueOf(IPPort);listen=new Dialog(this,登陸服務器,true);listen.addWindowListener(new WindowAdapter()public void windowClosing(WindowEvent e)passOk=false;HostName=null;passw.setText();out.println(。
35、&exit&);out.flush();listen.dispose(););JPanel p1=new JPanel(new BorderLayout();JPanel p11=new JPanel();JPanel p12=new JPanel();JPanel p13=new JPanel();JPanel p2=new JPanel(new FlowLayout();host.setFont(new Font(宋體,Font.PLAIN,12);hostText.setFont(new Font(宋體,Font.PLAIN,12);ipPort.setFont(new Font(宋體,。
36、Font.PLAIN,12);portText.setFont(new Font(宋體,Font.PLAIN,12);pass.setFont(new Font(宋體,Font.PLAIN,12);passw.setFont(new Font(宋體,Font.PLAIN,12);p11.add(host);p11.add(hostText);p12.add(ipPort);p12.add(portText);p13.add(pass);p13.add(passw);passw.addKeyListener(new KeyLis(this,1);p1.add(North,p11);p1.add(。
37、Center,p12);p1.add(South,p13);p2.add(ok1);p2.add(cancel1);listen.add(North,p1);listen.add(Center,p2);listen.setSize(150,160);listen.show();/接收文件流public void startCopy()tryString strnum=in.readLine();ByteNum=Integer.parseInt(strnum);byte data=new byte4096;copy=true;tryThread.sleep(1);catch(Exception e3)BufferedInputStream bufin=new BufferedInputStream(ClientSocket.getInputStream();/定義一個輸入流來接收文件的字節流int b;int j=0;Jrate=0;finish=0;while(finish+ByteNum)/ if(b=bufin.read()=-1)System.out.println(b+ +finish); break;/為什么不會出現-1b=bufin.read();if(b=0)dataj=(b。
總結
以上是生活随笔為你收集整理的远程桌面监控系统java_基于Java的远程桌面监控源代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C语言的下载和环境设置
- 下一篇: java信息管理系统总结_java实现科