testswing.py :  » Language-Interface » Java-Embedded-Python » jep-2.4 » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Language Interface » Java Embedded Python 
Java Embedded Python » jep 2.4 » testswing.py

from jep import *

from javax.swing import *
from java.awt import *
from java.awt.event import *

printStack(True)

# port of:
# http://java.sun.com/docs/books/tutorial/uiswing/learn/examples/SwingApplication.java

class SwingApplication:
    labelPrefix = "Number of button clicks: "
    numClicks   = 0
    label       = JLabel(labelPrefix + "0    ")

    def createComponents(self):
        button = JButton("I'm a Swing button!")
        button.setMnemonic(KeyEvent.VK_I)
        button.addActionListener(jproxy(self,
                                        ['java.awt.event.ActionListener']))
        self.label.setLabelFor(button)

        # An easy way to put space between a top-level container
        # and its contents is to put the contents in a JPanel
        # that has an "empty" border.

        pane = JPanel(GridLayout(0, 1))
        pane.add(button)
        pane.add(self.label)
        pane.setBorder(BorderFactory.createEmptyBorder(
            30, #top
            30, #left
            10, #bottom
            30)) #right

        return pane


    def actionPerformed(self, e):
        self.numClicks += 1
        self.label.setText(self.labelPrefix + str(self.numClicks))


# Create the GUI and show it.  For thread safety,
# this method should be invoked from the
# event-dispatching thread.
def createAndShowGUI():
    #Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(True)

    #Create and set up the window.
    frame = JFrame("SwingApplication")
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)

    app = SwingApplication()
    contents = app.createComponents()
    frame.getContentPane().add(contents, BorderLayout.CENTER)

    #Display the window.
    frame.pack()
    frame.setVisible(True)


if(__name__ == '__main__'):
    #Schedule a job for the event-dispatching thread:
    #creating and showing this application's GUI.
    createAndShowGUI()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.