JAVA 中 多文档编程


java中的多文档编程:
1,编写 单个文档的类: 继承 JInternalFrame
public class jmidframe extends JInternalFrame implements ActionListener,DocumentListener

2,为这个类添加文档事件:
this.addInternalFrameListener(new InternalFrameListener()

3,在当前JFrame 的构造函数中  构造JDesktopPane 并加入到JFrame中
JDesktopPane desk = null;

desk = new JDesktopPane();
add(desk, BorderLayout.CENTER);

4,新建一个多文档
jmidframe f = new jmidframe("新建" + (++mdifnumber));
desk.add(f);

5,遍历所有的多文档
JInternalFrame[] array = desk.getAllFrames();
jmidframe tempf = null;
for (int a = 0; a < array.length; a++)
{

 tempf = (jmidframe) array[a];
     
}

6,对当前文档操作:
temp = (jmidframe) desk.getSelectedFrame();// 获取当前活动的子窗体

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章