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();// 獲取當前活動的子窗體

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