0

I hava a Menu like this:

JMenu forum = new JMenu("Forum");
forum.addMenuListener( new MenuListener(){
    public void menuSelected(MenuEvent e) {

    }
    public void menuDeselected(MenuEvent e) {

    }
    public void menuCanceled(MenuEvent e) {

    }
});
menubar.add(forum);

and as menuSelected action, I want to redirect to a page, for example, page.html How can I do it?

  • possible duplicate of [Open a link in browser with java button?](http://stackoverflow.com/questions/10967451/open-a-link-in-browser-with-java-button) – FThompson Jun 21 '13 at 06:21
  • It is not a desktop application but it is a JApplet Menu, how can i do this in that case? – user1570194 Jun 21 '13 at 06:26
  • Be sure to mention that in your question next time, as that requires a completely difference approach. – FThompson Jun 21 '13 at 06:36

1 Answers1

0
 Desktop myDesktop=Desktop.getDesktop() 

public void menuSelected(MenuEvent e) {
       myDesktop.browse(uri);
    }

for Applet use below code(I get the code from here)

String link = "http://www."+source.getLabel()+".com";
      try {
         AppletContext a = getAppletContext();
         URL url = new URL(link);
         a.showDocument(url,"_blank");
      }
Sanjaya Liyanage
  • 4,706
  • 9
  • 36
  • 50
  • It is not a desktop application but it is a JApplet Menu, how can i do this in that case? Additionally, i want the current url to open the redirect url in the same tab – user1570194 Jun 21 '13 at 06:27
  • that didnt work either. I wrote the code below as you suggested but nothing shows up when I click Forum. The output shows "Forum Clicked" and does not show exception error message but no redirection too System.out.println("Forum clicked"); panel.removeAll(); String link = "http://www.google.com"; try { AppletContext a = getAppletContext(); URL url = new URL(link); a.showDocument(url,"_blank"); } catch (Exception err) { System.out.println("Not opening url"); } – user1570194 Jun 21 '13 at 06:39
  • It works now but do not open it in the same tab, but opens it like a pop-up – user1570194 Jun 21 '13 at 06:49