Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-07-2008, 03:20 PM
Senior Member
 
Join Date: Jun 2008
Posts: 121
Sarinam is on a distinguished road
[SOLVED] Chm
Hi All

How can i open a chm file through menu item.Plz help me..
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-07-2008, 06:51 PM
Senior Member
 
Join Date: Jun 2008
Posts: 317
masijade is on a distinguished road
Look at the Desktop (Desktop (Java Platform SE 6)) class, and you do know about ActionListeners? If not see How to Write an Action Listener (The Java™ Tutorials > Creating a GUI with JFC/Swing > Writing Event Listeners) and How to Use Menus (The Java™ Tutorials > Creating a GUI with JFC/Swing > Using Swing Components).

Google and especially the API docs (Java Platform SE 6) and Tutorials (The Java™ Tutorials) are your friends. Use them first.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-08-2008, 05:57 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,543
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-09-2008, 07:54 AM
Senior Member
 
Join Date: Jun 2008
Posts: 121
Sarinam is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 07-09-2008, 08:24 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,543
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
What you mean implement? Adding click events and stuff are you looking?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 07-09-2008, 08:54 AM
Senior Member
 
Join Date: Jun 2008
Posts: 121
Sarinam is on a distinguished road
Quote:
Originally Posted by Eranga View Post
What you mean implement? Adding click events and stuff are you looking?
Yes sir adding click event....
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 07-09-2008, 09:03 AM
Senior Member
 
Join Date: Jun 2008
Posts: 317
masijade is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 07-09-2008, 09:19 AM
Senior Member
 
Join Date: Jun 2008
Posts: 121
Sarinam is on a distinguished road
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..
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 07-09-2008, 09:32 AM
Senior Member
 
Join Date: Jun 2008
Posts: 317
masijade is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 07-09-2008, 09:36 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,543
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 07-09-2008, 09:48 AM
Senior Member
 
Join Date: Jun 2008
Posts: 121
Sarinam is on a distinguished road
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

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..
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 07-09-2008, 10:09 AM
Senior Member
 
Join Date: Jun 2008
Posts: 317
masijade is on a distinguished road
When the "actionCommand" equals "Open", use JFileChooser to have the user select the file then call Desktop.open(file). What is so hard here?
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 07-09-2008, 02:29 PM
Senior Member
 
Join Date: Jun 2008
Posts: 121
Sarinam is on a distinguished road
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.

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
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 07-10-2008, 05:22 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,543
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
You may help this.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #15 (permalink)  
Old 07-10-2008, 07:15 AM
Senior Member
 
Join Date: Jun 2008
Posts: 121
Sarinam is on a distinguished road
Quote:
Originally Posted by Eranga View Post
Sir i need some code example..

Plz give me some code example

Help me sir
Bookmark Post in Technorati
Reply With Quote
  #16 (permalink)  
Old 07-10-2008, 09:26 AM
Senior Member
 
Join Date: Jun 2008
Posts: 121
Sarinam is on a distinguished road
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

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(); } } }
Bookmark Post in Technorati
Reply With Quote
  #17 (permalink)  
Old 07-10-2008, 09:30 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,543
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #18 (permalink)  
Old 07-10-2008, 09:46 AM
Senior Member
 
Join Date: Jun 2008
Posts: 121
Sarinam is on a distinguished road
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..
Bookmark Post in Technorati
Reply With Quote
  #19 (permalink)  
Old 07-10-2008, 09:57 AM
Senior Member
 
Join Date: Jun 2008
Posts: 121
Sarinam is on a distinguished road
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.

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; } }
Bookmark Post in Technorati
Reply With Quote
  #20 (permalink)  
Old 07-10-2008, 10:02 AM
Senior Member
 
Join Date: Jun 2008
Posts: 121
Sarinam is on a distinguished road
Error is
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)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not