Page 1 of 2 12 LastLast
Results 1 to 20 of 39

Thread: [SOLVED] Chm

  1. #1
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default [SOLVED] Chm

    Hi All

    How can i open a chm file through menu item.Plz help me..

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Yes Sarinam, Google is the best place. You can find large number of examples on the web. At least try one of them and ask any question if you stuck with them.

    More important thing is, pay attention on what masijade says.

  4. #4
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Yes Sarinam, Google is the best place. You can find large number of examples on the web. At least try one of them and ask any question if you stuck with them.

    More important thing is, pay attention on what masijade says.
    Hello Sir

    Now i am abel to create a menu item but don't know how i impliment .chm file.Sir plz help me

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  6. #6
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    What you mean implement? Adding click events and stuff are you looking?
    Yes sir adding click event....

  7. #7
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Did you read those two tutorials and the API docs for Desktop that I posted?

    The last one shows you how to create menus and add ActionListeners to the Items.

    The second one shows you how to write an ActionListener.

    The first one (the API doc) shows you a class you can use to allow a system to "open" a "chm" file with the "default" program assigned to handle it.

    So, write an ActionListener that calls desktop and attach it to your menu item.

    That's it.

  8. #8
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    Quote Originally Posted by masijade View Post
    Did you read those two tutorials and the API docs for Desktop that I posted?

    The last one shows you how to create menus and add ActionListeners to the Items.

    The second one shows you how to write an ActionListener.

    The first one (the API doc) shows you a class you can use to allow a system to "open" a "chm" file with the "default" program assigned to handle it.

    So, write an ActionListener that calls desktop and attach it to your menu item.

    That's it.
    Can you give me some example code..

  9. #9
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Post your attempt at it, and we will help you correct it, but we are not going to do it for you. Those tutorials have enough code snippets as it is, anyway. And a little Google searching, I can guarantee, will turn up a code snippit for Desktop.

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Yep, shows your code where you stuck with and try to get our members help. I'm sure that too, you can easily find an example on the web related to your application.

  11. #11
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Yep, shows your code where you stuck with and try to get our members help. I'm sure that too, you can easily find an example on the web related to your application.
    Sir i just create a menu and i havn no idia how i add chm..here is code

    Java Code:
    import java.awt.*; 
    import java.awt.event.*; 
     
    public class MainWindow extends Frame { 
      public MainWindow() { 
        super("Menu Window"); 
        setSize(400, 400); 
        FileMenu fileMenu = new FileMenu(this); 
        HelpMenu helpMenu = new HelpMenu(this); 
        MenuBar mb = new MenuBar(); 
        mb.add(fileMenu); 
        mb.add(helpMenu); 
        setMenuBar(mb); 
        addWindowListener(new WindowAdapter() { 
          public void windowClosing(WindowEvent e) { 
            exit(); 
          } 
        }); 
      } 
     
      public void exit() { 
        setVisible(false); 
        dispose(); 
        System.exit(0); 
      } 
     
      public static void main(String args[]) { 
        MainWindow w = new MainWindow(); 
        w.setVisible(true); 
      } 
    } 
     
    class FileMenu extends Menu implements ActionListener { 
      MainWindow mw;  
      public FileMenu(MainWindow m) { 
        super("File"); 
        mw = m; 
        MenuItem mi; 
        add(mi = new MenuItem("Open")); 
        mi.addActionListener(this); 
        add(mi = new MenuItem("Close")); 
        mi.addActionListener(this); 
        add(mi = new MenuItem("Exit")); 
        mi.addActionListener(this); 
      } 
     
      public void actionPerformed(ActionEvent e) { 
        String item = e.getActionCommand(); 
        if (item.equals("Exit"))  
          mw.exit(); 
        else  
          System.out.println("Selected FileMenu " + item); 
      } 
    } 
     
    class HelpMenu extends Menu implements ActionListener { 
      MainWindow mw;  
      public HelpMenu(MainWindow m) { 
        super("Help"); 
        mw = m; 
        MenuItem mi; 
        add(mi = new MenuItem("Basics")); 
        mi.addActionListener(this); 
        add(mi = new MenuItem("Advanced")); 
        mi.addActionListener(this); 
        addSeparator(); 
        add(mi = new CheckboxMenuItem("Manual")); 
        mi.addActionListener(this); 
       
        Menu subMenu = new Menu("Miscellaneous"); 
        subMenu.add(mi = new MenuItem("Help")); 
        mi.addActionListener(this); 
        subMenu.add(mi = new MenuItem("Other Option")); 
        mi.addActionListener(this); 
        add(subMenu); 
      } 
      
      public void actionPerformed(ActionEvent e) { 
        String item = e.getActionCommand(); 
        if (item.equals("Basics")) 
          System.out.println("Basics"); 
        else if (item.equals("Help"))  
          System.out.println("Help"); 
      } 
    }
    Sir here how can i add chm..

  12. #12
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    When the "actionCommand" equals "Open", use JFileChooser to have the user select the file then call Desktop.open(file). What is so hard here?

  13. #13
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    Quote Originally Posted by masijade View Post
    When the "actionCommand" equals "Open", use JFileChooser to have the user select the file then call Desktop.open(file). What is so hard here?
    sir i am useing fileChooser like this.Can you how can i open now chm file.Becouse here code is working but file is not open.

    Java Code:
    private class OpenAction implements ActionListener {
            public void actionPerformed(ActionEvent ae) {
                int retval = m_fileChooser.showOpenDialog(m_Frame);
                if (retval == JFileChooser.APPROVE_OPTION) {
                    File chm = m_fileChooser.getSelectedFile();
                 
                }
            }
        }
    Plz help me

  14. #14
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  15. #15
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Sir i need some code example..

    Plz give me some code example

    Help me sir

  16. #16
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Sir now i am abel to open a file from drive.But it is open file direct from drive.But i need to open file through menuitem.here is code which is open file..Plz help me

    Java Code:
    public class Main {
    
    
    public Main() {
    }
    
    
    public static void main(String[] args) {
    
    try {
    //Runtime.getRuntime().exec("cmd /c start myfile.doc");
    //Runtime.getRuntime().exec("cmd /c start \"myfile.doc\"");
    //Runtime.getRuntime().exec("cmd /c start ma.txt");
    Runtime.getRuntime().exec("cmd /c startc:\\ma.txt");
    
    
    //Runtime.getRuntime().exec("cmd /c start myfile.xls");
    //Runtime.getRuntime().exec("cmd /c start myfile.pdf");
    //Runtime.getRuntime().exec("myfile.doc");
    }
    catch (Exception x) {
    x.printStackTrace();
    }
    catch (Error e) {
    e.printStackTrace();
    }
    
    
    }
    
    }

  17. #17
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    See, after few attempts you got the things. Now what you have to do is on menu item click event, do the same process. Do you know how to add events to menu items?

  18. #18
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    See, after few attempts you got the things. Now what you have to do is on menu item click event, do the same process. Do you know how to add events to menu items?
    Sir it is working but i want to add some option for browser..

  19. #19
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    See, after few attempts you got the things. Now what you have to do is on menu item click event, do the same process. Do you know how to add events to menu items?
    Sir this code is working but when i implements ActionListene on my original code then i got error. Here is my code how can i add ActionListene in this code.

    Java Code:
    
    import java.awt.*;
    
    public class MainMenu 
    {
    	Frame   m_Frame        = null;
    	boolean m_fInitialized = false;
    
    	
    
    	MenuBar mb;
    	
    
    
    	MenuItem MN_EXIT;	
    	Menu m3;	
    	
    	
    
    	
    	Menu m8;
    	MenuItem ID_HELP_ABOUT;	
    	MenuItem ID_HELP_TOPICS;
    	
    	
    	
    	// Constructor
    	//--------------------------------------------------------------------------
    	public MainMenu (Frame frame)
    	{
    		m_Frame = frame;
    	}
    
    	
    	// Initialization.
    	//--------------------------------------------------------------------------
    	public boolean CreateMenu()
    	{
    		// Can only init controls once
    		//----------------------------------------------------------------------
    		if (m_fInitialized || m_Frame == null)
    			return false;
    
    		// Create menubar and attach to the frame
    		//----------------------------------------------------------------------
    		mb = new MenuBar();
    		m_Frame.setMenuBar(mb);
    
    		// Create menu and menu items and assign to menubar
    		//----------------------------------------------------------------------
    	//
    	//		MN_EXIT = new MenuItem("Exit");
    	
    			m3 = new Menu("Settings");
    			mb.add(m3);
    				
    		
    	        
    	        
    	        MN_EXIT = new MenuItem("Exit");
    			m3.add(MN_EXIT);
    			
    			
    		
    			
    		
    		m8 = new Menu("Help");
    		mb.add(m8);
    		ID_HELP_TOPICS=new MenuItem("Help Topics");
    		m8.add(ID_HELP_TOPICS);
    	
    		ID_HELP_ABOUT = new MenuItem("About");
    		m8.add(ID_HELP_ABOUT);
    		
    		
    	
    		
    		
    			
    		m_fInitialized = true;
    		 
    		return true;
    	}
    }

  20. #20
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    Error is
    Java Code:
    Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem: 
    	The type MainMenu must implement the inherited abstract method ActionListener.actionPerformed(ActionEvent)
    
    	at main.MainMenu.actionPerformed(MainMenu.java:10)
    	at java.awt.MenuItem.processActionEvent(Unknown Source)
    	at java.awt.MenuItem.processEvent(Unknown Source)
    	at java.awt.MenuComponent.dispatchEventImpl(Unknown Source)
    	at java.awt.MenuComponent.dispatchEvent(Unknown Source)
    	at java.awt.MenuComponent.dispatchEventImpl(Unknown Source)
    	at java.awt.MenuComponent.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •