Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By superhaNds

Thread: Make a website open when a button is clicked.

  1. #1
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    130
    Rep Power
    0

    Default Make a website open when a button is clicked.

    i made a program that has a JMenuBar with some JMenuItems.

    i want to make a website pop up when someone clicks a JMenuItem.
    but i don't really know how, can you guys give me some help?

    this is the code for my JMenuItems and JMenuBar.

    Java Code:
    		JFrame frame = new JFrame("Calc");
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.setSize(500,500);
    		frame.setLocationRelativeTo(null);
    		frame.setLayout(new FlowLayout());
    	
    		
    		
    		JMenuBar bar = new JMenuBar();
    		JMenu about = new JMenu("About");
    		JMenu calcs = new JMenu("More calculators..");
    		JMenuItem me = new JMenuItem("me");
    		JMenuItem calcs2 = new JMenuItem("Skill calcs");
    	    frame.add(bar);
    		bar.add(about);
    		bar.add(calcs);
    		about.add(me);
    		calcs.add(calcs2);
    		bar.setVisible(true);
    		frame.setVisible(true);

  2. #2
    superhaNds is offline Senior Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    265
    Rep Power
    2

    Default Re: Make a website open when a button is clicked.

    first of all you need an action listener to the component you want and then implement the actionPerformed method. if you don't know how to do that check How to Write an Action Listener (The Java™ Tutorials > Creating a GUI With JFC/Swing > Writing Event Listeners)
    inside you probably need something like this

    java.awt.Desktop.getDesktop().browse(java.net.URI. create(the url you want as string);

    I think this works
    Fubarable likes this.

Similar Threads

  1. Replies: 6
    Last Post: 03-11-2012, 05:44 PM
  2. returning a string when button clicked
    By droidus in forum AWT / Swing
    Replies: 13
    Last Post: 02-02-2012, 04:50 AM
  3. Make GUI Button Open Another GUI
    By Feriscool in forum New To Java
    Replies: 7
    Last Post: 06-16-2011, 04:16 PM
  4. form appear after ok button clicked
    By sks in forum NetBeans
    Replies: 1
    Last Post: 06-01-2011, 09:50 AM
  5. Replies: 4
    Last Post: 02-16-2009, 04:20 PM

Posting Permissions

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