JAVA源代码105例 源代码使用说明 全部代码全部在JDK中调试成功

源代码在线查看: memmapjavaclient.java

软件大小: 1362 K
上传用户: awake2
关键词: JAVA 105 JDK 源代码
下载地址: 免注册下载 普通下载 VIP

相关代码

				package com.stanley.memmap;								import java.awt.*;				import java.awt.event.*;				import javax.swing.*;								public class MemMapJavaClient extends JFrame implements MemMapFileObserver{				  protected JButton btnClose;				  protected JTextArea textArea;				  protected MemMapProxy proxy;				  public static final String fileMappingObjName = "Mem_Map_File-{70122C30-0239-4f98-9D21-36885C8A8121}";								  //Construct the frame				  public MemMapJavaClient() {				    enableEvents(AWTEvent.WINDOW_EVENT_MASK);				    try {				      init();				    }				    catch(Exception e) {				      e.printStackTrace();				    }				  }				  //Component initialization				  private void init() throws Exception  {				    JPanel contentPane = (JPanel) this.getContentPane();				    contentPane.setLayout(new BorderLayout());								    textArea = new JTextArea();				    contentPane.add(textArea, BorderLayout.CENTER);				    btnClose = new JButton("Close");				    btnClose.addActionListener(new ActionListener() {				      public void actionPerformed(ActionEvent e) {					destroy();				      }				    });								    JPanel panelBtn = new JPanel();				    panelBtn.add(btnClose);				    contentPane.add(panelBtn, BorderLayout.SOUTH);								    proxy = new MemMapProxy(this);								    setSize(new Dimension(400, 300));				    setTitle("Test Memory Map File - Java Client");				  }								  private void destroy() {				    proxy.destroy();				    System.exit(0);				  }								  public void onDataReady() {				    int mapFilePtr = MemMapFile.openFileMapping(MemMapFile.FILE_MAP_READ, false,				        fileMappingObjName);				    if(mapFilePtr != 0) {				      int viewPtr = MemMapFile.mapViewOfFile(mapFilePtr,					  MemMapFile.FILE_MAP_READ, 0, 0, 0);				      if(viewPtr != 0) {					String content = MemMapFile.readFromMem(viewPtr);					textArea.setText(content);					MemMapFile.unmapViewOfFile(viewPtr);				      }				      MemMapFile.closeHandle(mapFilePtr);				    }				  }				  //Overridden so we can exit when window is closed				  protected void processWindowEvent(WindowEvent e) {				    super.processWindowEvent(e);				    if (e.getID() == WindowEvent.WINDOW_CLOSING) {				      destroy();				    }				  }				}			

相关资源