软著V1 基于Java的远程桌面监控源代码 交底_第1页
软著V1 基于Java的远程桌面监控源代码 交底_第2页
软著V1 基于Java的远程桌面监控源代码 交底_第3页
软著V1 基于Java的远程桌面监控源代码 交底_第4页
软著V1 基于Java的远程桌面监控源代码 交底_第5页
已阅读5页,还剩25页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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 .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 UIManager.setLookAndFeel(com.sun.java.swing.plaf.windows.WindowsLookAndFeel); catch(Exception e1) ne

4、w 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 JMenuIte

5、m(添加新主机); 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 = 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(); De

7、faultTreeCellRenderer 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; JTex

8、tField 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;

9、 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

10、(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);

11、 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.PLAI

12、N,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.s

13、etFont(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(mn

14、uFile); 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); cell

15、Renderer.setBackgroundNonSelectionColor(Color.white); cellRenderer.setBackgroundSelectionColor(Color.blue); cellRenderer.setBorderSelectionColor(Color.yellow); cellRenderer.setTextNonSelectionColor(Color.black); cellRenderer.setTextSelectionColor(Color.white); getContentPane().add(new JScrollPane(tr

16、ee),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.addActi

17、onListener(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);

18、 /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(); Add

19、computer.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

20、); 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+,JOp

21、tionPane.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.getSel

22、ectionPath(); if (treepath != null) DefaultMutableTreeNode selectionNode = (DefaultMutableTreeNode) treepath.getLastPathComponent(); TreeNode parent = (TreeNode)selectionNode.getParent(); if (parent != null) treeModel.removeNodeFromParent(selectionNode); / treeModel.reload(); catch(IOException E) el

23、se 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() A

24、ddHost=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(n

25、ew 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)

26、; 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)

27、; 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(200,150,400,130); AddHost.setSize(150,150); AddHost.show(); /服务器文件存储。public void down()

28、 try int result; existFile=false; result=Jsave.showSaveDialog(treePane); if(result=Jsave.APPROVE_OPTION) selectFile = Jsave.getSelectedFile(); /取得选择的文件 fileName=String.valueOf(selectFile); if(selectFile.exists() String message = 文件已经存在,要覆盖吗?; Object saveButton = OK,NO; JOptionPane save= new JOptionP

29、ane(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=true; else existFile=true; if(existFile) File outputFile = new Fil

30、e(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) BufferedInputStream bufin;public void connect() try disConnect=fa

31、lse; ClientSocket=new Socket(HostName,IPPort); InetAddress HostAddress=ClientSocket.getInetAddress(); ConnectIpText.setText(HostAddress.toString(); out=new PrintWriter(ClientSocket.getOutputStream(),true); in=new BufferedReader(new InputStreamReader(ClientSocket.getInputStream(); bufin=new BufferedI

32、nputStream(ClientSocket.getInputStream(); if(node1.getChildCount()0) out.println(&pass&); out.flush(); else String s1=new String(&nopass&); while(s1.equals(&nopass&) CP_dialog(); if(passOk) out.println(passw.getText(); out.flush(); passw.setText(); s1=in.readLine(); if(s1.equals(&nopass&) JOptionPan

33、e.showMessageDialog(getContentPane(), 密码错误,请重输); else disConnect=true; out.close(); in.close(); ClientSocket.close(); JOptionPane.showMessageDialog(getContentPane(), 目前处于非连接状态,请点击主机I重新建立连接); break; if(!disConnect) startPort=true; String s=in.readLine(); while(!s.equals(&over&) node1.add(new DefaultM

34、utableTreeNode(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(10); port

35、Text.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(&exit&); out.flush(); listen.dispose();

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论