Results 1 to 2 of 2
- 06-01-2013, 09:06 PM #1
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.
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);
- 06-01-2013, 09:42 PM #2Senior Member
- Join Date
- Apr 2013
- Rep Power
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
- By adiotrox in forum New To JavaReplies: 6Last Post: 03-11-2012, 05:44 PM
- By droidus in forum AWT / SwingReplies: 13Last Post: 02-02-2012, 04:50 AM
- By Feriscool in forum New To JavaReplies: 7Last Post: 06-16-2011, 03:16 PM
- By sks in forum NetBeansReplies: 1Last Post: 06-01-2011, 08:50 AM
- By mainy in forum AWT / SwingReplies: 4Last Post: 02-16-2009, 04:20 PM