I want a user to click on a button and then have a popup window for "HELP
And I want to add contents into "HELP"
I was wondering if someone could tell me or better show me
the code to how I get java to after a user clicks on the
button and pops up the help window?
public class popupTest extends Frame
implements ActionListener, MouseListener {
PopupMenu pm = new PopupMenu();
public static void main (String argv[]) {
new popupTest();
}
public popupTest() {
/*
** regular menu
*/
MenuItem item = new MenuItem("file-1");
item.addActionListener(this);
Menu m = new Menu("file");
m.add(item);
item = new MenuItem("file-2");
m.add(item);
MenuBar mb = new MenuBar();
mb.add(m);
/*
** label with a popup
*/
Label l = new Label("label");
addPopup(l, "label");
add(l, "North");
/*
** panel with popup
*/
Panel p = new Panel();
p.setBackground(new Color(0).red);
addPopup(p, "Panel");
add(p, "Center");
/*
** button with popup
*/
Button b = new Button("button");
addPopup(b, "button");
add(b, "South");
show();
}
public void actionPerformed(ActionEvent e) {
/*
** handle actions related to popup
*/
System.out.println("actionPerformed, event=" + e );
// System.out.println(" command=" + e.getActionCommand());
// System.out.println(" param=" + e.paramString());
// System.out.println(" source=" + e.getSource());
}
public void mouseClicked (MouseEvent e) { }
public void mouseEntered (MouseEvent e) { }
public void mouseExited (MouseEvent e) { }
public void mousePressed (MouseEvent e) {
mouseAction(e);
}
public void mouseReleased (MouseEvent e) {
mouseAction(e);
}
void mouseAction (MouseEvent e) {
/*
** determine if we have to show a Popup
*/
Component c = e.getComponent();
if (e.isPopupTrigger()) {
PopupMenu pm = getHash(c);
pm.show(c, c.getSize().width/2, c.getSize().height/2);
}
}
/*
** initialize a Popup for a particular Component
*/
Hashtable popupTable = new Hashtable();
void addPopup(Component c, String name) {
PopupMenu pm = new PopupMenu();
MenuItem mi = new MenuItem(name + "-1");
mi.addActionListener(this);
pm.add(mi);