易截截图软件、单文件、免安装、纯绿色、仅160KB

Java内部类访问外部对象的方法

  Java编程时,为类DialogTry2添加关闭窗口事件,我在构造方法中采用事件适配器来实现:
    this.addWindowListener(new WindowAdapter(){
        public void windowClosing(WindowEvent e){
            this.dispose();
        }
    });
  本意是为当前窗口(实际上为一个对话框)添加关闭窗口事件。但编译器报错说,new WindowAdapter()不存在dispose()方法。我明白过来,this.dispose()中的this不是窗口对象,而是适配器对象。那么怎样调用外部对象即窗口对象呢?既不能用super也没有outer。上网查一下,找到一个方法:在这个复合语句外面加一句:
    final DialogTry2 outer = this;
  然后把this.dispose();改为:
    outer.dispose();
  这样就好了。也看明白了怎么回事。原来this作为当前的对象可以这样调用啊,长见识了。
  改好的程序如下:
    final DialogTry2 outer = this;
    this.addWindowListener(new WindowAdapter(){
        public void windowClosing(WindowEvent e){
            outer.dispose();
        }
    });
  不记得从哪个网页看到的了,那页很复杂,讲了许多问题,我只从其中摘出这一条来。感谢那位网友。


相关文档:

java中垃圾回收算法

1)垃圾回收的两个关键要素:
发现无用对象。
回收无用对象的内存空间。
 
2)6种垃圾回收算法:
 
引用计数法,tracing 算法,compacting算法,copying 算法,generation算法,adaptive算法。
 
3)detail:
引用计数法(Reference Counting Collector)
引用计数法是唯一没有使用根集的垃圾回收的 ......

Java获取操作系统信息

SAMPLE:
import java.util.Properties;   
  
Properties props=System.getProperties(); //获得系统属性集   
String osName = props.getProperty("os.name"); //操作系统名称   
String osArch = props.getPropert ......

使用JAVA和C#开发Ribbon界面

Ribbon 原来出现在 Microsoft Office 2007 的 Word、Excel 和 Powerpoint 組件中,后来也被运用到 Windows 7 的一些附加组件等其它软件中,如画图和写字板。它是一个收藏了命令按钮和图标的面板。它把命令组织成一组"标签",每一组包含了相关的命令。每一个应用程序都有一个不同的标签组,展示了程序所提供 ......

Java选择题

选择题
3阅读一下程序:
Boolean a=false;
Boolean b=true;
Boolean c=(a&b)&&(!b);
Int result=b==false?1:2;
这段程序执行完后,c与result的值是(D)。
A  c=false; result=1;  B. c=true;result=2;
C.c=true;result=1   D. c=false; result=2
 
6.下述声明中哪种可防 ......

java 虚拟机运行时数据区域 Runtime Data Areas

The Java virtual machine defines various runtime data areas that are used during execution of a program. Some of these data areas are created on Java virtual machine start-up and are destroyed only when the Java virtual machine exits. Other data areas are per thread. Per-thread data areas are create ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号