要实现一个 JPopupMenu,最直接的方法就是创建一个继承自 MouseAdapter 的内部类,
然后对每个希望具有弹出式行为的组件,都添加一个该内部类的对象:
//: c14:Popup.java
// Creating popup menus with Swing.
// <applet code=Popup width=300 height=200></applet>
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import com.bruceeckel.swing.*;
public class Popup extends JApplet {
private JPopupMenu popup = new JPopupMenu();
private JTextField t = new JTextField(10);
public void init() {
Container cp = getContentPane();
cp.setLayout(new FlowLayout());
cp.add(t);
ActionListener al = new ActionListener() {
public
然后对每个希望具有弹出式行为的组件,都添加一个该内部类的对象:
//: c14:Popup.java
// Creating popup menus with Swing.
// <applet code=Popup width=300 height=200></applet>
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import com.bruceeckel.swing.*;
public class Popup extends JApplet {
private JPopupMenu popup = new JPopupMenu();
private JTextField t = new JTextField(10);
public void init() {
Container cp = getContentPane();
cp.setLayout(new FlowLayout());
cp.add(t);
ActionListener al = new ActionListener() {
public