Wrathchild
Technical User
can sombody help me with how to add actionlisteners to the items I'm adding to the menu? thanks!
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class ApplicationList3 extends JFrame
{
public ApplicationList3 ()
{
super ("Launcher");
setSize (150, 50);
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
//Store every application name in an array
String AppNames[] = { "App1", "App2", "App3", "App4" };
//Store every application path in an array
File[] AppPaths = new File[5];
AppPaths[0] = new File("http:test.jsp");
AppPaths[1] = new File("C:\\test.mde");
AppPaths[2] = new File("C:\\test2.mdb");
AppPaths[3] = new File("C:\\test3.mde");
//The third array, AppsLoaded, will only store those apps which are loaded on the machine and
//menu items will be created from these
String AppsLoaded[] = new String[5];
//add applications that everybody has; don't need to check for
AppsLoaded[0] = "App1";
int i;
for(i=1;i<4;i++){ //don't check App1, it's a web application, so everybody has it, so start at 1
if(AppPaths[i].exists()){
AppsLoaded[i] = AppNames[i];
System.out.println(AppsLoaded[i]);}
}
JMenuBar jmb = new JMenuBar ();
JMenu myMenu = new JMenu ("Application");
jmb.add(myMenu);
JMenuItem [] menulist = new JMenuItem[10];
for (i=0; i < 5; i++) {
menulist[i] = new JMenuItem(AppsLoaded[i]);
myMenu.add(menulist[i]);
}
myMenu.addSeparator ();
myMenu.add("Exit");
setJMenuBar (jmb);
setVisible (true);
}