예제 #1
0
    def run(self):
        #-----------------------------------------------------------------------
        # Create and set up the window.
        #-----------------------------------------------------------------------
        frame = JFrame('GlassPaneDemo')
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)

        #-----------------------------------------------------------------------
        # Start creating and adding components.
        #-----------------------------------------------------------------------
        changeButton = JCheckBox('Glass pane "visible"')
        changeButton.setSelected(0)

        #-----------------------------------------------------------------------
        # Set up the content pane, where the 'main GUI' lives.
        #-----------------------------------------------------------------------
        contentPane = frame.getContentPane()
        contentPane.setLayout(FlowLayout())
        contentPane.add(changeButton)
        contentPane.add(JButton('Button 1'))
        contentPane.add(JButton('Button 2'))

        #-----------------------------------------------------------------------
        # Set up the menu bar, which appears above the content pane.
        #-----------------------------------------------------------------------
        menuBar = JMenuBar()
        menu = JMenu('Menu')
        menu.add(JMenuItem('Do nothing'))
        menuBar.add(menu)
        frame.setJMenuBar(menuBar)

        #-----------------------------------------------------------------------
        # Set up the glass pane, which appears over both menu bar and
        # content pane and is an item listener on the change button
        #-----------------------------------------------------------------------
        myGlassPane = MyGlassPane(changeButton, menuBar, contentPane)
        changeButton.addItemListener(myGlassPane)
        frame.setGlassPane(myGlassPane)

        #-----------------------------------------------------------------------
        # Resize the frame to display the visible components contain therein,
        # and have the frame (application) make itself visisble.
        #-----------------------------------------------------------------------
        frame.pack()
        frame.setVisible(1)