-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
1.1, 1.1.1, 1.1.3, 1.1.4
-
None
-
x86
-
windows_95, windows_nt
Name: mc57594 Date: 03/06/97
Create JAVA application that creates a frame and attaches a
popup menu to a list component. Add a mouse handler to the list
component. In MouseHandler, when the menu is "shown", the
popup menu item text has been replaced with text contained within
the list items...
Sample source code for "ListPopupFrame.java" :
import java.awt.*;
import java.awt.event.*;
public class ListPopupFrame extends Frame {
// UI Components
Font font = new Font("Courier", Font.PLAIN, 12);
Panel resultsPanel;
PopupMenu popup;
ListPopupFrame(String t, int w, int h) {
super(t);
this.setLayout(new BorderLayout());
this.setFont(font);
this.resultsPanel = new Panel();
this.resultsPanel.setLayout(new BorderLayout());
List list = new List();
list.add("LIST ITEM 1");
list.add("LIST ITEM 2");
list.add("LIST ITEM 3");
list.add("LIST ITEM 4");
list.add("LIST ITEM 5");
this.resultsPanel.add("Center", list);
this.add("Center", resultsPanel);
Panel buttonPanel = new Panel();
this.add("South", buttonPanel);
buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 20,10));
Button addButton = new Button(" ADD ");
Button closeButton = new Button("CLOSE");
Button helpButton = new Button("HELP ");
buttonPanel.add(addButton);
buttonPanel.add(closeButton);
buttonPanel.add(helpButton);
AddHandler addHandler = new AddHandler(this);
addButton.addActionListener(addHandler);
CloseHandler closeHandler = new CloseHandler(this);
closeButton.addActionListener(closeHandler);
MenuItem mi;
this.popup = new PopupMenu();
mi = new MenuItem("Help");
this.popup.add(mi);
this.popup.addSeparator();
mi = new MenuItem("Add");
this.popup.add(mi);
mi.addActionListener(addHandler);
mi = new MenuItem("Delete");
this.popup.add(mi);
System.out.println("popup: " + this.popup);
MouseHandler mouseHandler = new MouseHandler(this);
list.add(popup);
list.addMouseListener(mouseHandler);
this.setSize(w, h);
this.show();
}
public static void main(String args[]) {
Frame f = new ListPopupFrame("List Popup", 640,400);
}
}
class AddHandler implements ActionListener {
ListPopupFrame frame;
AddHandler(ListPopupFrame f) {
frame = f;
}
public void actionPerformed(ActionEvent event) {
System.out.println("addHandler()");
}
}
class CloseHandler implements ActionListener {
Frame frame;
CloseHandler(Frame f){
frame = f;
}
public void actionPerformed(ActionEvent e) {
frame.setVisible(false);
frame.dispose();
System.exit(1);
}
}
class MouseHandler implements MouseListener {
ListPopupFrame frame;
MouseHandler(ListPopupFrame f) {
this.frame = f;
}
public void mouseClicked(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
System.out.println("mouseReleased()");
if (e.isPopupTrigger()) {
System.out.println("popup trigger at: " + e.getPoint());
if (this.frame.popup != null) {
System.out.println("popup: " + this.frame.popup);
System.out.println("component: " + e.getComponent());
for (int i=0; i<this.frame.popup.getItemCount(); i++) {
System.out.println("popup item: " + i + " str: " +
this.frame.popup.getItem(i).getLabel());
}
this.frame.popup.show(e.getComponent(), e.getX(), e.getY());
}
}
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
}
END SOURCE
I make with "make.bat" file whose contents is:
D:\Java\JDK1.1\bin\javac -classpath .;D:\Java\JDK1.1\lib\classes.zip -deprecation ListPopupFrame.java
I run with "run.bat" file whose contents is:
set CLASSPATH=%CLASSPATH%;d:\Java\Jdbc\classes;d:\java\jdk1.1\lib\classes.zip
D:\java\JDK1.1\bin\java ListPopupFrame
Debug info seems to indicate that the popup menus items should
still have appro text??
company - SAIC , email - ###@###.###
======================================================================
- duplicates
-
JDK-4072384 popup menus on buttons look funny
-
- Closed
-