KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > demo > MDI


1 /*
2  * SwingWT demo. Demonstrates how SwingWT deals with MDI
3  * interfaces.
4  *
5  * @author R. Rawson-Tetley
6  *
7  * $Log: MDI.java,v $
8  * Revision 1.6 2004/03/22 15:10:21 bobintetley
9  * JRootPane and JLayeredPane implementation
10  *
11  * Revision 1.5 2003/12/14 08:47:37 bobintetley
12  * Added useful comments and CVS log header
13  *
14  */

15
16
17 package demo;
18
19 import swingwt.awt.*;
20 import swingwtx.swing.*;
21 import swingwt.awt.event.*;
22 import swingwtx.swing.event.*;
23
24 public class MDI extends JFrame {
25     
26     public MDI() {
27         
28         final JDesktopPane jdp = new JDesktopPane();
29         this.setLayout(new BorderLayout());
30         this.add(jdp, BorderLayout.CENTER);
31         
32         JMenuBar bar = new JMenuBar();
33         JMenu mnuTest = new JMenu("Test");
34         JMenuItem mnuTestAdd = new JMenuItem("Add Window");
35         mnuTestAdd.addActionListener(new ActionListener() {
36             public void actionPerformed(ActionEvent e) {
37                 jdp.add(new SDIForm("Test"));
38             }
39         });
40         mnuTest.add(mnuTestAdd);
41         bar.add(mnuTest);
42         setJMenuBar(bar);
43         
44         show();
45         while(true){
46             try {
47                 Thread.sleep(1000);
48             } catch (InterruptedException JavaDoc e) {
49                 // TODO ×Ô¶¯Éú³É catch ¿é
50
e.printStackTrace();
51             }
52         }
53     }
54     
55     public static void main(String JavaDoc[] args) {
56        new MDI();
57     }
58     
59 }
60
61 class SDIForm extends JInternalFrame {
62     private static int counter = 1;
63     public SDIForm(String JavaDoc title) { this(); setTitle(title); }
64     public SDIForm() {
65         this.setTitle("An SDI Form");
66         this.setFrameIcon(new ImageIcon(getClass().getResource("/demo/pic.gif")));
67         this.getContentPane().setLayout(new GridBagLayout());
68         GridBagConstraints c = new GridBagConstraints(0, 0, 100, 100, 1, 1, GridBagConstraints.PAGE_END, 52, new Insets(0, 0, 10, 20), 5, 5);
69         getContentPane().add(new JLabel(getTitle() + " " + counter), c);
70         counter++;
71         setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
72         this.addInternalFrameListener(new InternalFrameListener() {
73                 public void internalFrameActivated(InternalFrameEvent e) {}
74                 public void internalFrameClosed(InternalFrameEvent e) {}
75                 public void internalFrameClosing(InternalFrameEvent e) {
76                     checkClose();
77                 }
78                 public void internalFrameDeactivated(InternalFrameEvent e) {}
79                 public void internalFrameDeiconified(InternalFrameEvent e) {}
80                 public void internalFrameIconified(InternalFrameEvent e) {}
81                 public void internalFrameOpened(InternalFrameEvent e) {}
82         });
83     }
84     
85     public void checkClose() {
86         if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(this, "Sure you wish to close?"))
87             dispose();
88     }
89     
90 }
91
Popular Tags