/*
* Copyright (C) 1996-2002 by ILOG.
* All rights reserved.
*
* This source code is an addition to the ILOG JViews Reference Manual
* delivered with the JViews library.
* It is supplied as an example to show you how to code with JViews.
* Feel free to use, copy or modify it within the framework of your
* JViews license agreement.
*/
/*
* $Id: DnDExample.java,v 1.10 2002/10/17 15:47:41 laudazzi Exp $
*/package dnd;import ilog.views.*;
import ilog.views.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.dnd.*;
import java.awt.datatransfer.*;
import javax.swing.*;
import java.util.ArrayList;/*
* This example launches a <code>JFrame</code> containing two <code>JInternalFrame</code>. You can drag and drop
* <code>IlvGraphic</code> from one frame to another.
*/
public class DnDExample extends JFrame {
private IlvManager mg1;
private IlvManager mg2;
private boolean main = false;
private static ArrayList desktops = new ArrayList(); public static void main(String[] arg) {
new DnDExample();
} public DnDExample() {
super("Drag'n'Drop Sample");
setSize(800, 685);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
DnDExample.this.dispose();//这里的this
desktops.remove(DnDExample.this);
if (desktops.size() == 0 || main)
System.exit(0);
}
});
}
}
请问,这里的this 是什么用法?我查了dispose() 是java.awt.Window类下的方法。因为这里的this是在匿名类里调用的,所以要这么用DnDExample.this来调用匿名类外部的方法dispose()。这里的DnDExample.this是指的DnDExample类的实例吧?但是怎么和java.awt.Window类扯上关系了呢?不知道是怎么回事?还是我理解的有问题?
* Copyright (C) 1996-2002 by ILOG.
* All rights reserved.
*
* This source code is an addition to the ILOG JViews Reference Manual
* delivered with the JViews library.
* It is supplied as an example to show you how to code with JViews.
* Feel free to use, copy or modify it within the framework of your
* JViews license agreement.
*/
/*
* $Id: DnDExample.java,v 1.10 2002/10/17 15:47:41 laudazzi Exp $
*/package dnd;import ilog.views.*;
import ilog.views.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.dnd.*;
import java.awt.datatransfer.*;
import javax.swing.*;
import java.util.ArrayList;/*
* This example launches a <code>JFrame</code> containing two <code>JInternalFrame</code>. You can drag and drop
* <code>IlvGraphic</code> from one frame to another.
*/
public class DnDExample extends JFrame {
private IlvManager mg1;
private IlvManager mg2;
private boolean main = false;
private static ArrayList desktops = new ArrayList(); public static void main(String[] arg) {
new DnDExample();
} public DnDExample() {
super("Drag'n'Drop Sample");
setSize(800, 685);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
DnDExample.this.dispose();//这里的this
desktops.remove(DnDExample.this);
if (desktops.size() == 0 || main)
System.exit(0);
}
});
}
}
请问,这里的this 是什么用法?我查了dispose() 是java.awt.Window类下的方法。因为这里的this是在匿名类里调用的,所以要这么用DnDExample.this来调用匿名类外部的方法dispose()。这里的DnDExample.this是指的DnDExample类的实例吧?但是怎么和java.awt.Window类扯上关系了呢?不知道是怎么回事?还是我理解的有问题?
-java.awt.Component
-java.awt.Container
-java.awt.Window
-java.awt.Frame
-javax.swing.JFrame所以JFrame也有dispose()方法啊。
就这么简单
java.awt.Frame继承自java.awt.Window
类层次:
java.awt.Window
java.awt.Frame
javax.swing.JFrame
DnDExample
查看下API文档就清楚的事情
thx all together!