2012-06-26 5 views
0

자바로 브라우저에서 이벤트를 수신 할 수 있습니까? 주된 임무는 마우스 오른쪽 클릭의 팝업 메뉴에 "파일로 복사"명령을 추가하는 것입니다. 이 명령은 브라우저에서 선택한 텍스트를 메모장의 특정 텍스트 파일에 대한 winword (선택 가능한 텍스트)에 추가해야합니다. 트레이에 아이콘을 추가하는 코드를 시도했습니다. 그러나 나는 그것이 나의 작업 해결을 위해 개발 될 수 있는지 모른다.브라우저의 텍스트를 브라우저에서 직접 텍스트 파일로 복사하기위한 Windows 배경의 자바

import java.awt.*; 
import java.awt.event.*; 
public class SystemTrayTest 
{ 

    public SystemTrayTest() 
    { 

     final TrayIcon trayIcon; 

     if (SystemTray.isSupported()) { 

      SystemTray tray = SystemTray.getSystemTray(); 
      Image image = Toolkit.getDefaultToolkit().getImage("tray.gif"); 

      MouseListener mouseListener = new MouseListener() { 

       public void mouseClicked(MouseEvent e) { 
        System.out.println("Tray Icon - Mouse clicked!");     
       } 
       public void mouseEntered(MouseEvent e) { 
        System.out.println("Tray Icon - Mouse entered!");     
       } 
       public void mouseExited(MouseEvent e) { 
        System.out.println("Tray Icon - Mouse exited!");     
       } 
       public void mousePressed(MouseEvent e) { 
        System.out.println("Tray Icon - Mouse pressed!");     
       } 
       public void mouseReleased(MouseEvent e) { 
        System.out.println("Tray Icon - Mouse released!");     
       } 

      }; 

      ActionListener exitListener = new ActionListener() { 
       public void actionPerformed(ActionEvent e) { 
        System.out.println("Exiting..."); 
        System.exit(0); 
       } 
      }; 

      PopupMenu popup = new PopupMenu(); 
      MenuItem defaultItem = new MenuItem("Exit"); 
      defaultItem.addActionListener(exitListener); 
      popup.add(defaultItem); 

      trayIcon = new TrayIcon(image, "Tray Demo", popup); 

      ActionListener actionListener = new ActionListener() { 
       public void actionPerformed(ActionEvent e) { 
        trayIcon.displayMessage("Action Event", 
         "An Action Event Has Been Peformed!", 
         TrayIcon.MessageType.INFO); 
       } 
      }; 

      trayIcon.setImageAutoSize(true); 
      trayIcon.addActionListener(actionListener); 
      trayIcon.addMouseListener(mouseListener); 

      // Depending on which Mustang build you have, you may need to uncomment 
      // out the following code to check for an AWTException when you add 
      // an image to the system tray. 

      // try { 
         tray.add(trayIcon); 
      // } catch (AWTException e) { 
      //  System.err.println("TrayIcon could not be added."); 
      // } 

     } else { 
      System.err.println("System tray is currently not supported."); 
     } 
    } 

    /** 
    * @param args the command line arguments 
    */ 
    public static void main(String[] args) 
    { 
     SystemTrayTest main = new SystemTrayTest(); 
    } 

} 

답변