菜单定义的事件是打开frameA
如何实现,不管点击多少次菜单,只要frameA打开了,就不再重新打开?

解决方案 »

  1.   

    使用单实例。frame实例的变量需要是静态的,每次获得变量的时候,如果变量已经实例化过,看情况是否重新对数据初始化;如果变量未实例化,实例化之。
    获得变量后,把它setVisible(true).
      

  2.   

    class xxx{
        private frameA frame = new frameA();
        ....    button.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                 if( !frame.isShowing() ){
                       frame.setVisible(true);
                 }
            }
        )};    ....
    }
      

  3.   

    自己做一个哈西表类,该类中有两个静态方法:
    import java.util.*;public class Bag
    {
    static Hashtable ht = new Hashtable();
    public static void put(String id,Object O)
    {
    ht.put(id,O);
    }
    public static Object get(String id)
    {
    return ht.get(id);
    }
    }
    直接调用方法就好。
    frameA A = (frameA)Bag.get("frameA");
    if(frameA==null)
    {
    A= new frameA(this);
    Bag.put("frameA",frameA);
    }
    else
    {
    frameA.setVisible(true);
    }
      

  4.   

    A= new frameA(this);
    不好意思,frameA()中不需要带参数this,自己写习惯了