I am creating a GUI with Jmenu; it has jmenu elements that will do something when clicked. This is problem. I looked and looked, but I canβt figure out how to get him to do something when they press him. Also, I'm kind of like a noob, so if you could do it in a pretty simple way, that would be great!
Here is the code:
import java.awt.Color; import java.awt.Component; import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import javax.swing.*; public abstract class windowMaker extends JFrame implements ActionListener { private JMenu menuFile; public static void main(String[] args) { createWindow(); } public static void createWindow() { JFrame frame = new JFrame(); frame.setTitle("*Game Title* Beta 0.0.1"); frame.setSize(600, 400); frame.setLocation(100, 100); frame.setVisible(true); frame.setResizable(false); frame.setDefaultCloseOperation(EXIT_ON_CLOSE); frame.setJMenuBar(windowMaker.menuBarCreator()); frame.add(windowMaker.setTitle()); } public static void launchURL(String s) { String s1 = System.getProperty("os.name"); try { if (s1.startsWith("Windows")) { Runtime.getRuntime() .exec((new StringBuilder()) .append("rundll32 url.dll,FileProtocolHandler ") .append(s).toString()); } else { String as[] = { "firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape" }; String s2 = null; for (int i = 0; i < as.length && s2 == null; i++) if (Runtime.getRuntime() .exec(new String[] { "which", as[i] }).waitFor() == 0) s2 = as[i]; if (s2 == null) throw new Exception("Could not find web browser"); Runtime.getRuntime().exec(new String[] { s2, s }); } } catch (Exception exception) { System.out .println("An error occured while trying to open the web browser!\n"); } } public static JMenuBar menuBarCreator() {
BTW: I want the website setting (let's just work with this for now) to use the launchURL method; I know that it works.
java user-interface swing jmenuitem jmenu
Pulsepanda
source share