def __init__(self): self.frame=swing.JFrame(title="My Frame", size=(300,300)) self.frame.defaultCloseOperation=swing.JFrame.EXIT_ON_CLOSE; self.frame.layout=awt.BorderLayout() self.panel1=swing.JPanel(awt.BorderLayout()) self.panel2=swing.JPanel(awt.GridLayout(4,1)) self.panel2.preferredSize = awt.Dimension(10,100) self.panel3=swing.JPanel(awt.BorderLayout()) self.title=swing.JLabel("Text Rendering") self.button1=swing.JButton("Print Text", actionPerformed=self.printMessage) self.button2=swing.JButton("Clear Text", actionPerformed=self.clearMessage) self.textField=swing.JTextField(30) self.outputText=swing.JTextArea(4,15) self.panel1.add(self.title) self.panel2.add(self.textField) self.panel2.add(self.button1) self.panel2.add(self.button2) self.panel3.add(self.outputText) self.frame.contentPane.add(self.panel1, awt.BorderLayout.PAGE_START) self.frame.contentPane.add(self.panel2, awt.BorderLayout.CENTER) self.frame.contentPane.add(self.panel3, awt.BorderLayout.PAGE_END)
def __init__(self, parent): self.parent = parent Panel = swing.JPanel() Panel.layout = awt.BorderLayout() Panel.border = swing.BorderFactory.createTitledBorder( "Payload Encoder") self.text = swing.JTextField(actionPerformed=self.encodePayload) Panel.add(self.text, Panel.layout.PAGE_START) self.textArea = swing.JTextArea() scrollPane = swing.JScrollPane(self.textArea) Panel.add(scrollPane, Panel.layout.CENTER) Panel1 = swing.JPanel() Panel1.layout = awt.BorderLayout() Panel1.border = swing.BorderFactory.createTitledBorder( "Payload Parser") self.text1 = swing.JTextField(actionPerformed=self.parsePayload) Panel1.add(self.text1, Panel1.layout.PAGE_START) self.textArea1 = swing.JTextArea() scrollPane1 = swing.JScrollPane(self.textArea1) Panel1.add(scrollPane1, Panel1.layout.CENTER) self.splitPane = swing.JSplitPane(swing.JSplitPane.VERTICAL_SPLIT) self.splitPane.setDividerLocation(250) self.splitPane.setLeftComponent(Panel) self.splitPane.setRightComponent(Panel1) self.parent.addTabPanel("Options", self.splitPane)
def friendsList(self, username): self.window = swing.JFrame(username) self.window.layout = awt.BorderLayout() statusPanel = swing.JPanel() statusPanel.layout = awt.GridLayout(4, 1) # Set status placeholder UI statusPanel.border = swing.BorderFactory.createTitledBorder("Status") buttonGroup = swing.ButtonGroup() radioButton = swing.JRadioButton("Away", actionPerformed=self.radioCallback) buttonGroup.add(radioButton) statusPanel.add(radioButton) radioButton = swing.JRadioButton("Here", actionPerformed=self.radioCallback) buttonGroup.add(radioButton) statusPanel.add(radioButton) #Wizard of Oz incoming chat request radioButton = swing.JButton("Page Boss", actionPerformed=self.callBoss) buttonGroup.add(radioButton) statusPanel.add(radioButton) statusPanel.add(self.status) #statusPanel.add(swing.JButton("Update Status", actionPerformed=self.updateStatus)) #Buddy list panel = swing.JPanel() panel.layout = awt.BorderLayout() panel.border = swing.BorderFactory.createTitledBorder("Friends Online") ##TODO: fix threading so that friends load before the window print self.friendsData self.friendsData.append('guest') print '2' self.list = swing.JList(self.friendsData) panel.add("Center", swing.JScrollPane(self.list)) launchChatButton = swing.JButton("Launch chat?", actionPerformed=self.launchChatOut) panel.add("South", launchChatButton) self.window.windowClosing = self.goodbye pane = JScrollPane() pane.getViewport().add(self.list) panel.add(pane) self.window.add("North", statusPanel) self.window.add("South", panel) self.window.pack() self.window.visible = True return self.window
def createGui (self): # build the GUI self.layout = awt.BorderLayout() progB = self.__progressBar = \ swing.JProgressBar(0, 100, stringPainted=1); inf = self.__inputField = swing.JTextField(5) inl = swing.JLabel("Calculate value of:", swing.JLabel.RIGHT) inl.labelFor = inf outf = self.__outputArea = swing.JTextArea() outl = swing.JLabel("Result:", swing.JLabel.RIGHT) outl.labelFor = outf calcb = self.__calcButton = \ swing.JButton("Calculate", actionPerformed=self.doCalc, enabled=1, mnemonic=awtevent.KeyEvent.VK_C) cancelb = self.__cancelButton = \ swing.JButton("Cancel", actionPerformed=self.doCancel, enabled=0, mnemonic=awtevent.KeyEvent.VK_L) vl = ValueLayout(5, 5) inp = swing.JPanel(vl) vl.setLayoutAlignmentX(inp, 0.2) inp.add(inl); inp.add(inf, inl) self.add(inp, awt.BorderLayout.NORTH) vl = ValueLayout(5, 5) outp = swing.JPanel(vl) vl.setLayoutAlignmentX(outp, 0.2) outp.add(outl); outp.add(swing.JScrollPane(outf), outl) xoutp = swing.JPanel(awt.BorderLayout()) xoutp.add(progB, awt.BorderLayout.NORTH) xoutp.add(outp, awt.BorderLayout.CENTER) self.add(xoutp, awt.BorderLayout.CENTER) sp = swing.JPanel(awt.BorderLayout()) bp = swing.JPanel() bp.add(calcb) bp.add(cancelb) sp.add(bp, awt.BorderLayout.NORTH) sl = self.__statusLabel = swing.JLabel(" ") sp.add(sl, awt.BorderLayout.SOUTH) self.add(sp, awt.BorderLayout.SOUTH)
def __init__(self): # Launches the login screen, initializes self.window, the primary frame self.done = False self.friendsData = [''] self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.chatHistory = {} self.usernameField = JTextField('guest', 20) self.status = JTextField(text='setStatus', editable=True) self.portNumber = "6666" self.IP = "127.0.0.1" self.window = swing.JFrame("Catchy Messenger Name") self.chatWindow = swing.JFrame() self.window.windowClosing = self.goodbye tempPanel = swing.JPanel() tempPanel = awt.BorderLayout() loginPage = JPanel(GridLayout(0, 2)) self.window.add(loginPage) loginPage.add(JLabel("Enter today's username", SwingConstants.RIGHT)) loginPage.add(self.usernameField) textIP = swing.JTextField(text=self.IP, editable=True) #chatHistory = swing.JTextArea(text = "new chat instance!", editable = False, lineWrap = True, size = (300,1)) loginButton = JButton('Log in', actionPerformed=self.login) loginPage.add(JLabel("")) loginPage.add(loginButton) loginPage.add(textIP) loginPage.add(JLabel("Change IP from default?", SwingConstants.LEFT)) loginPage.add(swing.JTextField(text=self.portNumber, editable=True)) loginPage.add(JLabel("Change Port from default?")) self.window.pack() self.window.visible = True return
def StatusWindow(): win = swing.JFrame("Printer Status") win.size = (200, 75 + (count * 25)) win.contentPane.background = awt.Color.white win.contentPane.setLayout(awt.BorderLayout()) win.contentPane.add(list, awt.BorderLayout.CENTER) win.show()
def addOptions(self): self.optpanel = swing.JPanel(layout=awt.BorderLayout()) self.add(self.optpanel, awt.BorderLayout.EAST) self.commentcheck = swing.JCheckBox( COMMENTS, horizontalTextPosition=swing.SwingConstants.LEFT) self.commentcheck.setSelected(SHOWCOMMENTS) self.optpanel.add(self.commentcheck, awt.BorderLayout.EAST) # self.grbcheck = swing.JCheckBox('Gurobi:', horizontalTextPosition = swing.SwingConstants.LEFT)#w# # self.grbcheck.setSelected(False)#w# self.LPbox = swing.Box(swing.BoxLayout.LINE_AXIS) self.LPbox.add( swing.Box.createRigidArea(awt.Dimension(2 * BORDERWIDTH, 0))) self.LPbox.add(swing.JLabel(SOLVER)) self.solverbox = swing.JComboBox(Data.Problem.SOLVERS) self.solverbox.addActionListener(self.SolverSwitcher(self)) self.LPbox.add(self.solverbox) self.LPbox.add(swing.Box.createRigidArea(awt.Dimension(BORDERWIDTH, 0))) self.trimcheck = swing.JCheckBox( REDUCE, horizontalTextPosition=swing.SwingConstants.LEFT) self.LPbox.add(self.trimcheck) self.LPbox.add(swing.Box.createRigidArea(awt.Dimension(BORDERWIDTH, 0))) self.optpanel.add(self.LPbox, awt.BorderLayout.WEST) #CENTER->WEST
def showMismatchTable(self): jf = swing.JFrame() jf.setDefaultCloseOperation(jf.DISPOSE_ON_CLOSE) cp = jf.getContentPane() cp.setLayout(awt.BorderLayout()) jt = swing.JTable(self._dtm) jt.setAutoResizeMode(jt.AUTO_RESIZE_ALL_COLUMNS) drend = self._dftcr() jt.setDefaultRenderer(java.lang.Object, drend) count = self._dtm.getRowCount() tmp_label = swing.JLabel(java.lang.String.valueOf(count)) psize = tmp_label.getPreferredSize() column = jt.getColumn("") column.setPreferredWidth(psize.width + 10) column.setMaxWidth(psize.width + 10) sp = swing.JScrollPane(jt) sp.addComponentListener(drend) cp.add(sp, awt.BorderLayout.CENTER) jb = swing.JButton("Close") jb.actionPerformed = lambda event: jf.dispose() cp.add(jb, awt.BorderLayout.SOUTH) jf.pack() g.app.gui.center_dialog(jf) jf.visible = 1
def __init__(self, gui): self.gui = gui self.server = gui.client.server self.boardFrame = swing.JInternalFrame( 'Chinese Chess', 1, 1, 1, 1, internalFrameClosing=self.onClosing, defaultCloseOperation=swing.JInternalFrame.DO_NOTHING_ON_CLOSE) setColours(game_cchess_boardgui, gui.config.state) self.board = game_cchess_boardgui.Canvas() self.board.setDoMove(self.server.doMove) self.board.setBoard(cchess.Board()) self.boardFrame.contentPane.layout = awt.BorderLayout() self.boardFrame.contentPane.add(self.board) self.statusBar = swing.JLabel('temp') self.boardFrame.contentPane.add(self.statusBar, 'South') gui.main.add(self.boardFrame) self.boardFrame.show() self.boardFrame.pack() self.boardFrame.size = 300, 300 self.boardFrame.invalidate() self.suggestFrame = games.SuggestionFrame(AI(), self.server, self.gui.main) print 'made gui'
def __init__(self, id, client): self.id = id self.client = client self.events = {} self.actions = {} self.frame = swing.JFrame() self.frame.contentPane.layout = awt.BorderLayout() self.attr = ThingAttrModel(self) self.attrTable = ThingAttrTable(self.attr, client) self.attrTable.preferredSize = 200, 75 # self.frame.contentPane.add(swing.JScrollPane(self.attrTable)) self.frame.contentPane.add(self.attrTable) self.actionList = swing.Box.createVerticalBox() self.actionControls = {} self.frame.contentPane.add(self.actionList, 'North') self.eventBox = swing.Box.createVerticalBox() self.frame.contentPane.add(self.eventBox, 'South') self.frame.setDefaultCloseOperation( swing.WindowConstants.DO_NOTHING_ON_CLOSE) self.frame.windowClosing = self.clickedOnClose self.frame.show() self.frame.setSize(awt.Dimension(200, 200)) self.frame.validate()
def registerExtenderCallbacks(self, callbacks): # keep a reference to our callbacks object self._callbacks = callbacks # set our extension name self._callbacks.setExtensionName("Payload Parser") # build UI self._jPanel = swing.JPanel() self._jPanel.layout = awt.BorderLayout() self._jPanel.border = swing.BorderFactory.createTitledBorder( "Input characters to display payload strings with characters included or excluded" ) inputPanel = swing.JPanel() inputPanel.layout = awt.BorderLayout() radioPanel = swing.JPanel() self.text1 = swing.JTextField(actionPerformed=self.radioCallback) inputPanel.add(self.text1, inputPanel.layout.CENTER) buttonGroup = swing.ButtonGroup() self._radioButtonInclude = swing.JRadioButton("Include") buttonGroup.add(self._radioButtonInclude) radioPanel.add(self._radioButtonInclude) self._radioButtonExclude = swing.JRadioButton("Exclude") buttonGroup.add(self._radioButtonExclude) radioPanel.add(self._radioButtonExclude) self._radioButtonInclude.setSelected(True) inputPanel.add(radioPanel, inputPanel.layout.LINE_END) self._jPanel.add(inputPanel, self._jPanel.layout.PAGE_START) self.textArea = swing.JTextArea() scrollPane = swing.JScrollPane(self.textArea) self._jPanel.add(scrollPane, self._jPanel.layout.CENTER) boxVertical = swing.Box.createVerticalBox() saveLabel = swing.JLabel( "Save Payloads (In Burp Root Dir): Can be Imported into Intruder") boxVertical.add(saveLabel) boxHorizontal = swing.Box.createHorizontalBox() saveLabel2 = swing.JLabel("Save As:") boxHorizontal.add(saveLabel2) self._saveTextField = swing.JTextField('', 30) boxHorizontal.add(self._saveTextField) submitSaveButton = swing.JButton('Save', actionPerformed=self.savePayload) boxHorizontal.add(submitSaveButton) boxVertical.add(boxHorizontal) self._jPanel.add(boxVertical, self._jPanel.layout.PAGE_END) # add the custom tab to Burp's UI self._callbacks.addSuiteTab(self) return
def clickMeCallback(self, event): dialog = swing.JFrame("You clicked the button!") dialog.contentPane.layout = awt.BorderLayout() dialog.contentPane.add(swing.JLabel("Text was: " + self.field.text)) dialog.size = (400, 200) dialog.show() print "Text is ", self.field.text self.field.text = ""
def __init__(self): self.frame=swing.JFrame(title="Simple Jython Interpreter", size=(600,500)) self.frame.defaultCloseOperation=swing.JFrame.EXIT_ON_CLOSE; self.frame.layout=awt.BorderLayout() self.panel1=swing.JPanel(awt.BorderLayout()) self.panel2=swing.JPanel(awt.BorderLayout()) self.title=swing.JLabel("Jython Code") self.title2 = swing.JLabel("Interpreter Output") self.button1=swing.JButton("Run", actionPerformed=self.printMessage) self.button2=swing.JButton("Clear Output", actionPerformed=self.clearMessage) self.buttonPane = swing.JPanel() self.buttonPane.layout = swing.BoxLayout(self.buttonPane, swing.BoxLayout.LINE_AXIS) self.buttonPane.border = swing.BorderFactory.createEmptyBorder(0, 10, 10, 10) self.buttonPane.add(swing.Box.createHorizontalGlue()) self.buttonPane.add(self.button1) self.buttonPane.add(swing.Box.createRigidArea(awt.Dimension(10, 0))) self.buttonPane.add(self.button2) self.textField=swing.JTextArea(4,15) self.textField.lineWrap = True self.scrollPaneOne = swing.JScrollPane(self.textField) self.scrollPaneOne.verticalScrollBarPolicy = swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS self.outputText=swing.JTextArea(4,15) self.outputText.lineWrap = True self.outputText.editable = False self.scrollPane2 = swing.JScrollPane(self.outputText) self.scrollPane2.verticalScrollBarPolicy = swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS self.panel1.add(self.title, awt.BorderLayout.PAGE_START) self.panel1.add(self.scrollPaneOne, awt.BorderLayout.CENTER) self.panel2.add(self.title2, awt.BorderLayout.PAGE_START) self.panel2.add(self.scrollPane2, awt.BorderLayout.CENTER) self.splitPane = swing.JSplitPane(swing.JSplitPane.VERTICAL_SPLIT, self.panel1, self.panel2) self.splitPane.oneTouchExpandable = True self.minimumSize = awt.Dimension(50, 100) self.panel1.minimumSize = self.minimumSize self.panel2.minimumSize = self.minimumSize self.frame.contentPane.add(self.splitPane, awt.BorderLayout.CENTER) self.frame.contentPane.add(self.buttonPane, awt.BorderLayout.PAGE_END)
def __init__(self, debugger): swing.JFrame.__init__(self, title='JESDB Variable Watcher') # variables correspond to columns on the right self.history = ExecHistory(debugger) self.controlPanel = DBControlPanel(debugger) self.table = swing.JTable(self.history) scrollPane = swing.JScrollPane(self.table) self.contentPane.setLayout(awt.BorderLayout()) scrollPane.preferredSize = (200, 400) self.contentPane.add(scrollPane, awt.BorderLayout.CENTER) self.contentPane.add(self.controlPanel, awt.BorderLayout.EAST) self.pack()
def setAction(self, actionid, name): if actionid in self.actionControls.keys(): self.actionControls[actionid].text = name else: b = swing.JButton(name, actionPerformed=lambda e, aid=actionid, server= self.client.server: server.doAction(aid)) if not self.isOwnedByMe(): b.enabled = 0 self.actionControls[actionid] = b p = swing.JPanel(layout=awt.BorderLayout()) p.add(b) self.actionList.add(p) self.frame.contentPane.validate()
def thingChangedAction(self, id=None): self.actionBox.removeAll() if self.thing != None: list = self.thing.actions.items() list.sort(lambda a, b: cmp(a[1], b[1])) for id, name in list: b = swing.JButton(name) b.actionPerformed = lambda x, aid=id, server=self.server: server.doAction( aid) p = swing.JPanel(layout=awt.BorderLayout()) p.add(b) self.actionBox.add(p) self.validate()
def __init__(self, debugger): self.debugger = debugger self.controlPanel = DBControlPanel(self.debugger) self.history = JESExecHistoryModel.JESExecHistoryModel() self.table = WatcherTable(self.history) self.rendererComponent = swing.JLabel(opaque=1) self.table.setDefaultRenderer(Object, MyRenderer()) self.history.setColumnWidths(self.table) self.scrollPane = swing.JScrollPane(self.table) self.scrollPane.verticalScrollBar.model.stateChanged = self.stateChanged self.setLayout(awt.BorderLayout()) self.add(self.scrollPane, awt.BorderLayout.CENTER) self.add(self.controlPanel, awt.BorderLayout.NORTH) self.lastScrollMaximum = None
def __init__(self): super.__init__(self, layout=awt.BorderLayout()) self.arglayout = awt.CardLayout() self.argpanel = swing.JPanel(layout=self.arglayout) self.add(self.argpanel, awt.BorderLayout.CENTER) # self.setMaximumSize(awt.Dimension(self.getWidth(), 25))#t# self.program = DEFAULT self.writers = {} self.addWriters() self.addOptions() self.switch(self.program) self.addOptions()
def launchChatIn(self, event): #Launches one chat window per conversation. TODO: less wizard of oz chatWindow = swing.JFrame("The Boss") self.chatHistory['The Boss'] = chatInstance() chatWindow.contentPane.layout = awt.BorderLayout() #self.chatHistory = swing.JTextArea(text = "new chat instance!", editable = False, lineWrap = True, size = (300,1)) chatHistoryPanel = swing.JPanel() chatHistoryPanel.add( swing.JScrollPane(self.chatHistory['The Boss'].messageText)) chatWindow.contentPane.add(chatHistoryPanel) #TODO: key listener so [return] enters text #TODO: more complicated than boss parroting action entryPanel = swing.JPanel() chatWindow.contentPane.add("South", entryPanel) entryPanel.layout = awt.BorderLayout() #TODO change data structure of chatHistory to hold multiple chats self.field = swing.JTextField() entryPanel.add(self.field) entryPanel.add( "East", swing.JButton("Enter Text", actionPerformed=self.enterText)) chatWindow.pack() chatWindow.show() self.chatWindow.visible = False
def launchChatOut(self, event): # format: ["INVITE", [user1, user2, ...]] print self.list.selectedValue self.sock.send(pickle.dumps(["INVITE", [str(self.list.selectedValue)]])) #TODO: build real chat client functionality dialog = swing.JFrame("Server error") dialog.contentPane.layout = awt.BorderLayout() dialog.contentPane.add( swing.JLabel("Internal error. " + self.list.selectedValue + " is not online.")) dialog.size = (400, 200) dialog.show() return
def __init__(self): swing.JFrame.__init__(self) self.title = 'Chinese Chess' self.windowClosing = self.onExit self.board = boardCanvas.Canvas() self.board.setBoard(cchess.Board()) self.contentPane.layout = awt.BorderLayout() self.contentPane.add(self.board) self.statusBar = swing.JLabel('...initializing game...') self.contentPane.add(self.statusBar, 'South') self.board.setDoMove(self.doMove) self.show() self.pack()
def __init__(self): JFrame.__init__(self, title="ImageWebVisor", size=(550, 510), windowClosing=exit) self.contentPane.layout = awt.BorderLayout() self.dir = JTextField(preferredSize=(400, 30)) boton = JButton("Ver/View", preferredSize=(100, 30), actionPerformed=self.pres) panel = JPanel() panel.add(self.dir) panel.add(boton) self.label = JLabel("", horizontalAlignment=SwingConstants.CENTER, verticalAlignment=SwingConstants.CENTER) self.bar = JScrollPane(self.label) self.contentPane.add(panel, awt.BorderLayout.NORTH) self.contentPane.add(self.bar, awt.BorderLayout.CENTER) self.dir.text = "URL de la Imagen a ver/ URL of imagen to view"
def __init__(self, server): swing.JPanel.__init__(self) self.server = server self.layout = awt.BorderLayout() self.actionBox = swing.Box.createVerticalBox() self.eventBox = swing.Box.createVerticalBox() self.attrBox = swing.Box.createVerticalBox() self.attr = {} self.attrButtons = {} self.choosingColor = awt.Color(0, 255, 0) self.add(self.attrBox, 'North') self.add(self.actionBox) self.add(self.eventBox, 'South') self.thing = None self.defaultBorder = swing.BorderFactory.createTitledBorder( '[Selected Card]') self.border = self.defaultBorder self.field = None self.chooseButton = None
def getParams(self): # GUI to get future % of subbasin redeveloped, curve number, and release rate # Initialize window for UI frame = swing.JFrame("Set conditions of redeveloped portion of subbasin", layout=awt.BorderLayout()) frame.setDefaultCloseOperation(swing.JFrame.EXIT_ON_CLOSE) # Create panel that includes three text entry fields for % redeveloped, curve number, and release rate futureparams = swing.JPanel(layout=awt.GridLayout(3,2)) inbutton = swing.JPanel() futureparams.add(swing.JLabel('Percent Redevelopment ')) rd = swing.JTextField('', 5) futureparams.add(rd) futureparams.add(swing.JLabel('Future Curve Number ')) cn = swing.JTextField('', 5) futureparams.add(cn) futureparams.add(swing.JLabel('Release Rate ')) rr = swing.JTextField('', 5) futureparams.add(rr) # Create panel for button that stores the values entered setButton = swing.JButton('Set parameters', actionPerformed=(lambda x: self.setParams(rd, cn, rr, frame))) self.setParams(rd, cn, rr, frame) # Add panels to the window and make the window visible frame.add(futureparams, awt.BorderLayout.NORTH) inbutton.add(setButton) frame.add(inbutton, awt.BorderLayout.SOUTH) # setButton.addMouseListener(awt.event.MouseListener.mouseClicked(self, self.setParams(rd, cn, rr, frame))) frame.pack()
"""\ A silly little calculator implemented in JPython using Java components for the UI. Rony G. Flatscher, 2006-08-08 """ import java from java import awt p = bsf.lookupBean('centerPanel') p.setLayout(awt.BorderLayout()) p.add("Center", java.awt.Label("Middle from Jython")) p.add("North", java.awt.TextField("north text from Jython")) p.add("South", java.awt.TextField("south text from Jython")) p.add("East", java.awt.Button("inner east from Jython")) p.add("West", java.awt.Button("inner west from Jython")) p.setBackground(java.awt.Color.orange) f = p.getParent() f.setTitle("Hello from Jython (title reset from Jython)")
def __init__(self, owner): self.owner = owner swing.JPanel.__init__(self, layout=awt.BorderLayout())
from java import awt # get access to Java class libraries from pawt import swing # they look like Python modules here labels = ['0', '1', '2', '+', # labels for calculator buttons '3', '4', '5', '-', # will be used for a 4x4 grid '6', '7', '8', '*', '9', '.', '=', '/' ] keys = swing.JPanel(awt.GridLayout(4, 4)) # do Java class library magic display = swing.JTextField() # Python data auto-mapped to Java def push(event): # callback for regular keys display.replaceSelection(event.actionCommand) def enter(event): # callback for the '=' key display.text = str(eval(display.text)) # use Python eval() to run expr display.selectAll() for label in labels: # build up button widget grid key = swing.JButton(label) # on press, invoke Python funcs if label == '=': key.actionPerformed = enter else: key.actionPerformed = push keys.add(key) panel = swing.JPanel(awt.BorderLayout()) # make a swing panel panel.add("North", display) # text plus key grid in middle panel.add("Center", keys) swing.test(panel) # start in a GUI viewer
def __init__(self): ######################################################### # # set up the overall frame (the window itself) # self.window = swing.JFrame("Swing Sampler!") self.window.windowClosing = self.goodbye self.window.contentPane.layout = awt.BorderLayout() ######################################################### # # under this will be a tabbed pane; each tab is named # and contains a panel with other stuff in it. # tabbedPane = swing.JTabbedPane() self.window.contentPane.add("Center", tabbedPane) ######################################################### # # The first tabbed panel will be named "Some Basic # Widgets", and is referenced by variable 'firstTab' # firstTab = swing.JPanel() firstTab.layout = awt.BorderLayout() tabbedPane.addTab("Some Basic Widgets", firstTab) # # slap in some labels, a list, a text field, etc... Some # of these are contained in their own panels for # layout purposes. # tmpPanel = swing.JPanel() tmpPanel.layout = awt.GridLayout(3, 1) tmpPanel.border = swing.BorderFactory.createTitledBorder( "Labels are simple") tmpPanel.add(swing.JLabel("I am a label. I am quite boring.")) tmpPanel.add( swing.JLabel( "<HTML><FONT COLOR='blue'>HTML <B>labels</B></FONT> are <I>somewhat</I> <U>less boring</U>.</HTML>" )) tmpPanel.add( swing.JLabel("Labels can also be aligned", swing.JLabel.RIGHT)) firstTab.add(tmpPanel, "North") # # Notice that the variable "tmpPanel" gets reused here. # This next line creates a new panel, but we reuse the # "tmpPanel" name to refer to it. The panel that # tmpPanel used to refer to still exists, but we no # longer have a way to name it (but that's ok, since # we don't need to refer to it any more). # tmpPanel = swing.JPanel() tmpPanel.layout = awt.BorderLayout() tmpPanel.border = swing.BorderFactory.createTitledBorder( "Tasty tasty lists") # # Note that here we stash a reference to the list in # "self.list". This puts it in the scope of the object, # rather than this function. This is because we'll be # referring to it later from outside this function, so # it needs to be "bumped up a level." # listData = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ] self.list = swing.JList(listData) tmpPanel.add("Center", swing.JScrollPane(self.list)) button = swing.JButton("What's Selected?") button.actionPerformed = self.whatsSelectedCallback tmpPanel.add("East", button) firstTab.add("Center", tmpPanel) tmpPanel = swing.JPanel() tmpPanel.layout = awt.BorderLayout() # # The text field also goes in self, since the callback # that displays the contents will need to get at it. # # Also note that because the callback is a function inside # the SwingSampler object, you refer to it through self. # (The callback could potentially be outside the object, # as a top-level function. In that case you wouldn't # use the 'self' selector; any variables that it uses # would have to be in the global scope. # self.field = swing.JTextField() tmpPanel.add(self.field) tmpPanel.add( swing.JButton("Click Me", actionPerformed=self.clickMeCallback), "East") firstTab.add(tmpPanel, "South") ######################################################### # # The second tabbed panel is next... This shows # how to build a basic web browser in about 20 lines. # secondTab = swing.JPanel() secondTab.layout = awt.BorderLayout() tabbedPane.addTab("HTML Fanciness", secondTab) tmpPanel = swing.JPanel() tmpPanel.add(swing.JLabel("Go to:")) self.urlField = swing.JTextField(40, actionPerformed=self.goToCallback) tmpPanel.add(self.urlField) tmpPanel.add(swing.JButton("Go!", actionPerformed=self.goToCallback)) secondTab.add(tmpPanel, "North") self.htmlPane = swing.JEditorPane("http://www.google.com", editable=0, hyperlinkUpdate=self.followHyperlink, preferredSize=(400, 400)) secondTab.add(swing.JScrollPane(self.htmlPane), "Center") self.statusLine = swing.JLabel("(status line)") secondTab.add(self.statusLine, "South") ######################################################### # # The third tabbed panel is next... # thirdTab = swing.JPanel() tabbedPane.addTab("Other Widgets", thirdTab) imageLabel = swing.JLabel( swing.ImageIcon( net.URL("http://www.gatech.edu/images/logo-gatech.gif"))) imageLabel.toolTipText = "Labels can have images! Every widget can have a tooltip!" thirdTab.add(imageLabel) tmpPanel = swing.JPanel() tmpPanel.layout = awt.GridLayout(3, 2) tmpPanel.border = swing.BorderFactory.createTitledBorder( "Travel Checklist") tmpPanel.add( swing.JCheckBox("Umbrella", actionPerformed=self.checkCallback)) tmpPanel.add( swing.JCheckBox("Rain coat", actionPerformed=self.checkCallback)) tmpPanel.add( swing.JCheckBox("Passport", actionPerformed=self.checkCallback)) tmpPanel.add( swing.JCheckBox("Airline tickets", actionPerformed=self.checkCallback)) tmpPanel.add( swing.JCheckBox("iPod", actionPerformed=self.checkCallback)) tmpPanel.add( swing.JCheckBox("Laptop", actionPerformed=self.checkCallback)) thirdTab.add(tmpPanel) tmpPanel = swing.JPanel() tmpPanel.layout = awt.GridLayout(4, 1) tmpPanel.border = swing.BorderFactory.createTitledBorder("My Pets") # # A ButtonGroup is used to indicate which radio buttons # go together. # buttonGroup = swing.ButtonGroup() radioButton = swing.JRadioButton("Dog", actionPerformed=self.radioCallback) buttonGroup.add(radioButton) tmpPanel.add(radioButton) radioButton = swing.JRadioButton("Cat", actionPerformed=self.radioCallback) buttonGroup.add(radioButton) tmpPanel.add(radioButton) radioButton = swing.JRadioButton("Pig", actionPerformed=self.radioCallback) buttonGroup.add(radioButton) tmpPanel.add(radioButton) radioButton = swing.JRadioButton("Capybara", actionPerformed=self.radioCallback) buttonGroup.add(radioButton) tmpPanel.add(radioButton) thirdTab.add(tmpPanel) self.window.pack() self.window.show()
def __init__(self, title, host, port, service): # create window win = swing.JFrame(title, size=(800, 480)) win.setDefaultCloseOperation(swing.JFrame.EXIT_ON_CLOSE) win.contentPane.layout = awt.BorderLayout(10, 10) # add scrollable textfield status = swing.JTextPane(preferredSize=(780, 400)) status.setAutoscrolls(True) status.setEditable(False) status.setBorder(swing.BorderFactory.createEmptyBorder(20, 20, 20, 20)) paneScrollPane = swing.JScrollPane(status) paneScrollPane.setVerticalScrollBarPolicy( swing.JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED) win.contentPane.add(paneScrollPane, awt.BorderLayout.CENTER) # add server button self.started = "Start Server" self.stopped = "Stop Server" self.serverButton = swing.JButton(self.started, preferredSize=(150, 20), actionPerformed=self.controlServer) # add client button self.clientButton = swing.JButton("Invoke Method", preferredSize=(150, 20), actionPerformed=self.runClient) self.clientButton.enabled = False # position buttons buttonPane = swing.JPanel() buttonPane.setLayout( swing.BoxLayout(buttonPane, swing.BoxLayout.X_AXIS)) buttonPane.setBorder( swing.BorderFactory.createEmptyBorder(0, 10, 10, 10)) buttonPane.add(swing.Box.createHorizontalGlue()) buttonPane.add(self.serverButton) buttonPane.add(swing.Box.createRigidArea(awt.Dimension(10, 0))) buttonPane.add(self.clientButton) win.contentPane.add(buttonPane, awt.BorderLayout.SOUTH) # add handler that writes log messages to the status textfield txtHandler = TextFieldLogger(status) logger = logging.getLogger("") logger.setLevel(logging.DEBUG) formatter = logging.Formatter('%(asctime)s - %(message)s') txtHandler.setFormatter(formatter) logger.addHandler(txtHandler) # setup server self.service_name = service self.url = "http://%s:%d" % (host, port) self.server = ThreadedAmfServer(host, port, self.service_name) # center and display window on the screen win.pack() us = win.getSize() them = awt.Toolkit.getDefaultToolkit().getScreenSize() newX = (them.width - us.width) / 2 newY = (them.height - us.height) / 2 win.setLocation(newX, newY) win.show()
g.drawString("Invalid Expression", x, y) def setExpression(self, e): "@sig public void setExpression(java.lang.String e)" try: self.function = eval('lambda x: ' + e) except: self.function = None self.repaint() if __name__ == '__main__': def enter(e): graph.setExpression(expression.text) expression.caretPosition = 0 expression.selectAll() p = awt.Panel(layout=awt.BorderLayout()) graph = Graph() p.add(graph, 'Center') expression = awt.TextField(text='(sin(3*x)+cos(x))/2', actionPerformed=enter) p.add(expression, 'South') import pawt pawt.test(p, size=(300, 300)) enter(None)