def main_menu(): """ Main menu which is always open Parameters ---------- None Returns ------- JFrame Main menu with JButtons calling other functions """ frame = JFrame("GMM Image Quality Calculator") nButtons = 4 frame.setSize(100 * nButtons, 300) frame.setLayout(GridLayout(nButtons, 1)) # Define JButtons get_user_params_JB = JButton("Load image and settings", actionPerformed = User_Dialogs.get_user_params) fit_GMM_JB = JButton("Fit Gaussian Mixture Model", actionPerformed = User_Dialogs.fit_GMM) show_as_RT_JB = JButton("Show SNR and CNR as Results Table", actionPerformed = User_Dialogs.show_as_RT) show_thresholded_JB = JButton("Show thresholded stack", actionPerformed = User_Dialogs.show_thresholded) # Add JButtons to frame frame.add(get_user_params_JB) frame.add(fit_GMM_JB) frame.add(show_as_RT_JB) frame.add(show_thresholded_JB) frame.setVisible(True)
def initial(): global f ##文件 global txt global number_of_occurrence reload(sys) sys.setdefaultencoding('utf-8') ctr.init() ctr.set_value('flag', 0) ctr.set_value('reload_check', 0) ctr.set_value('world_boss_check', 0) ctr.set_value('raid_check', 0) #ctr.set_value('raid_check',None) number_of_occurrence = 0 ctr.set_value('max_level_check', None) ctr.set_value('return_check', 0) ticks = time.time() date = time.strftime("%Y_%m_%d_%H_%M_%S", time.localtime(ticks)) + '_日誌' f = open(date + '.txt', 'w', 0) frame = JFrame("Log") txt = JTextArea(19, 55) scrollPane = JScrollPane(txt) ##frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) frame.setLocation(2000, 100) frame.setSize(480, 450) frame.setLayout(FlowLayout()) ##label = JLabel('記錄:') scrollPane.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER) ##frame.add(label) frame.add(scrollPane) frame.setVisible(True)
def show(): """ adapted from here: http://wiki.gephi.org/index.php/Toolkit_-_Reuse_the_Preview_Applet""" from javax.swing import JFrame from java.awt import BorderLayout pc = PreviewController pc.refreshPreview(); # New Processing target, get the PApplet target = pc.getRenderTarget("processing") applet = target.getApplet() applet.init() # Refresh the preview and reset the zoom try: pc.render(target) except Exception: # throws sun.dc.pr.PRError: sun.dc.pr.PRError: setPenT4: invalid pen transformation (singular) pass target.refresh() target.resetZoom() # Add the applet to a JFrame and display frame = JFrame("Preview") frame.setLayout(BorderLayout()) # frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) frame.add(applet, BorderLayout.CENTER) frame.pack() frame.setVisible(True)
def run(self): frame = JFrame('AbsoluteLayout', defaultCloseOperation=JFrame.EXIT_ON_CLOSE) # Replace the default Layout Manager frame.setLayout(None) # Information defining button title, location & size data = [['A', 20, 10, 0, 0], ['B', 40, 40, 10, 10], ['C', 80, 20, 20, 20]] # For each data entry, create & position a button insets = frame.getInsets() for item in data: button = frame.add(JButton(item[0])) size = button.getPreferredSize() button.setBounds(insets.left + item[1], insets.top + item[2], size.width + item[3], size.height + item[4]) # Define the application frame size frame.setSize( 300 + insets.left + insets.right, # frame width 150 + insets.top + insets.bottom # frame height ) # Make the frame visible frame.setVisible(1)
class CoordinateChooser: def buttonPressed(self, event): # The OK button was pressed; proceed to compute and plot moment arms # relative to the selected coordinate. coordIndex = self.cb.selectedIndex coordName = self.data[coordIndex] self.frame.setVisible(False) ComputeAndPlotMomentArms(coordIndex) def __init__(self): # Populate and display window for selecting a coordinate from the # specified motion (kinematics) file. self.frame = JFrame("Coordinate chooser") self.frame.setSize(350, 100) self.frame.setLayout(BorderLayout()) self.frame.setLocationRelativeTo(None) self.data = coordList self.cb = JComboBox(self.data, preferredSize=(200, 25)) self.frame.add(self.cb, BorderLayout.WEST) btn = JButton('OK', preferredSize=(75, 25), actionPerformed=self.buttonPressed) self.frame.add(btn, BorderLayout.EAST) self.label = JLabel('Please select the coordinate to use in the \ moment arm calculations', preferredSize=(325, 50)) self.frame.add(self.label, BorderLayout.NORTH) self.frame.setVisible(True)
def show(): """ adapted from here: http://wiki.gephi.org/index.php/Toolkit_-_Reuse_the_Preview_Applet""" from javax.swing import JFrame from java.awt import BorderLayout pc = PreviewController pc.refreshPreview() # New Processing target, get the PApplet target = pc.getRenderTarget("processing") applet = target.getApplet() applet.init() # Refresh the preview and reset the zoom try: pc.render(target) except Exception: # throws sun.dc.pr.PRError: sun.dc.pr.PRError: setPenT4: invalid pen transformation (singular) pass target.refresh() target.resetZoom() # Add the applet to a JFrame and display frame = JFrame("Preview") frame.setLayout(BorderLayout()) # frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) frame.add(applet, BorderLayout.CENTER) frame.pack() frame.setVisible(True)
def initResultados(self): diag = JFrame() self.lineas = list() self.areaResultados = JTextArea() numLineas = self.readResultados() panelResultados = JPanel() #panelResultados.setAutoscrolls(True) panelResultados.setBorder(BorderFactory.createEtchedBorder()) panelResultados.setLayout(GridLayout(0, 1)) pane = JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED) pane.viewport.view = self.areaResultados #pane.getViewport().add(panelResultados) diag.setTitle("RESULTADOS OBTENIDOS") diag.setSize(1000, 450) diag.setLayout(BorderLayout()) diag.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) diag.setLocationRelativeTo(None) diag.setVisible(True) panelResultados.add(pane) diag.add(panelResultados, BorderLayout.CENTER)
def changePasswordForm(check): global frame global tfOldPassword global tfNewPassword global tfConfirmPassword global value value = check frame = JFrame("Change Password") frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) frame.setSize(500, 350) frame.setLocation(200, 200) frame.setLayout(None) frame.setVisible(True) panel = JPanel() panel.setSize(500, 350) panel.setLocation(0, 0) panel.setLayout(None) panel.setVisible(True) panel.setBackground(Color.LIGHT_GRAY) heading = JLabel("Change Password") heading.setBounds(200, 30, 150, 40) lbOldPassword = JLabel("Old Password") lbNewPassword = JLabel("New Password") lbConfirmPassword = JLabel("Confirm Password") tfOldPassword = JTextField() tfNewPassword = JTextField() tfConfirmPassword = JTextField() lbOldPassword.setBounds(50, 100, 150, 30) lbNewPassword.setBounds(50, 150, 150, 30) lbConfirmPassword.setBounds(50, 200, 150, 30) tfOldPassword.setBounds(220, 100, 150, 30) tfNewPassword.setBounds(220, 150, 150, 30) tfConfirmPassword.setBounds(220, 200, 150, 30) btnSave = JButton("Save", actionPerformed=clickSave) btnCancel = JButton("Cancel", actionPerformed=clickCancel) btnSave.setBounds(350, 280, 100, 30) btnCancel.setBounds(50, 280, 100, 30) panel.add(heading) panel.add(lbOldPassword) panel.add(lbNewPassword) panel.add(lbConfirmPassword) panel.add(tfOldPassword) panel.add(tfNewPassword) panel.add(tfConfirmPassword) panel.add(btnSave) panel.add(btnCancel) frame.add(panel)
def addCourse(): global tfCourseName global tfCourseId global tfCourseFee global frame global btnEnter frame = JFrame("Add Course ") frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) frame.setSize(450, 450) frame.setLocation(200, 200) frame.setLayout(None) frame.setVisible(True) panel = JPanel() panel.setSize(450, 450) panel.setLocation(0, 0) panel.setLayout(None) panel.setVisible(True) panel.setBackground(Color.LIGHT_GRAY) heading = JLabel("ADD COURSE") heading.setBounds(200, 30, 150, 40) lbCourseName = JLabel("Course Name ") lbCourseId = JLabel("Course Id") lbCourseFee = JLabel(" Course Fee") tfCourseName = JTextField() tfCourseId = JTextField() tfCourseFee = JTextField() lbCourseName.setBounds(70, 120, 130, 30) lbCourseId.setBounds(70, 170, 130, 30) lbCourseFee.setBounds(70, 220, 130, 30) tfCourseName.setBounds(220, 120, 150, 30) tfCourseId.setBounds(220, 170, 150, 30) tfCourseFee.setBounds(220, 220, 150, 30) btnEnter = JButton("Enter", actionPerformed=clickAddCourseFee) btnEnter.setBounds(300, 300, 100, 40) btnCancel = JButton("Cancel", actionPerformed=clickCancel) btnCancel.setBounds(70, 300, 100, 40) panel.add(heading) panel.add(lbCourseName) panel.add(lbCourseId) panel.add(lbCourseFee) panel.add(tfCourseFee) panel.add(tfCourseName) panel.add(tfCourseId) panel.add(tfCourseFee) panel.add(btnEnter) panel.add(btnCancel) frame.add(panel)
def studentLogined(stObj): global panel global table global heading global frame frame = JFrame("Student Page ") frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) frame.setSize(500, 600) frame.setLocation(200, 200) frame.setLayout(None) panel = JPanel() panel.setSize(500, 580) panel.setLocation(0, 20) panel.setLayout(None) panel.setVisible(True) panel.setBackground(Color.WHITE) heading = JLabel() heading.setBounds(210, 10, 200, 30) table = JTable() table.setBounds(0, 50, 500, 470) sp = JScrollPane(table, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS) bar = JMenuBar() profile = JMenu("Profile") showProfile = JMenuItem("Show Profile", actionPerformed=clickShowStudentProfile) changePassword = JMenuItem("Change Password", actionPerformed=changeStudentPassword) profile.add(showProfile) profile.add(changePassword) bar.add(profile) attendence = JMenu("Attendence") showAllAttendence = JMenuItem("Show All Attendence", actionPerformed=clickAllAttendence) showAttendenceInMonth = JMenuItem("show attendence in month", actionPerformed=clickAttendenceInMonth) attendence.add(showAllAttendence) attendence.add(showAttendenceInMonth) bar.add(attendence) logout = JMenuItem("logout", actionPerformed=clickLogout) bar.add(logout) panel.add(table) frame.setJMenuBar(bar) frame.add(panel) frame.setVisible(True)
def get_file_name(): frame = JFrame("Filename") frame.setLocation(100, 100) frame.setSize(500, 400) frame.setLayout(None) fc = JFileChooser() result = fc.showOpenDialog(frame) if not result == JFileChooser.APPROVE_OPTION: return None file_name = fc.getSelectedFile() return file_name
def show_errors(self, label): """Display error messages.""" top_label = JLabel(label, JLabel.CENTER) frame = JFrame(self.ext_name) frame.setSize(550, 300) frame.setLayout(GridLayout(1, 1)) frame.add(top_label) frame.setLocationRelativeTo(None) frame.setVisible(True)
def show_pannel(self): # BP_STDOUT.println("Event code: %s" % self.contextMenuInvocation.getInputEvent()) # self.scannerInstance.show_pannel.show() window = JFrame() window.setLayout(None) window.setTitle("Xcrpter") window.setSize(720, 540) window.setLocationRelativeTo(None) window.setResizable(True) window.setContentPane(self.scannerInstance.xpannel) window.setVisible(True) self.scannerInstance.xpannel.setPlain("") self.scannerInstance.xpannel.setVisible(True)
def install(helper): print('install called'); frame = JFrame("Please Input Values") frame.setLocation(100,100) frame.setSize(500,400) frame.setLayout(None) lbl1 = JLabel("Input1: ") lbl1.setBounds(60,20,60,20) txt1 = JTextField(100) txt1.setBounds(130,20,200,20) lbl2 = JLabel("Input2: ") lbl2.setBounds(60,50,100,20) txt2 = JTextField(100) txt2.setBounds(130,50,200,20) lbl3 = JLabel("Input3: ") lbl3.setBounds(60,80,140,20) txt3 = JTextField(100) txt3.setBounds(130,80,200,20) lbl4 = JLabel("Input4: ") lbl4.setBounds(60,110,180,20) txt4 = JTextField(100) txt4.setBounds(130,110,200,20) def getValues(event): print "clicked" ScriptVars.setGlobalVar("Input1",str(txt1.getText())) print(ScriptVars.getGlobalVar("Input1")) ScriptVars.setGlobalVar("Input2",str(txt2.getText())) print(ScriptVars.getGlobalVar("Input2")) ScriptVars.setGlobalVar("Input3",str(txt3.getText())) print(ScriptVars.getGlobalVar("Input3")) ScriptVars.setGlobalVar("Input4",str(txt4.getText())) print(ScriptVars.getGlobalVar("Input4")) btn = JButton("Submit", actionPerformed = getValues) btn.setBounds(160,150,100,20) frame.add(lbl1) frame.add(txt1) frame.add(lbl2) frame.add(txt2) frame.add(btn) frame.add(lbl3) frame.add(txt3) frame.add(lbl4) frame.add(txt4) frame.setVisible(True)
def install(helper): print('install called') frame = JFrame("Please Input Values") frame.setLocation(100, 100) frame.setSize(500, 400) frame.setLayout(None) lbl1 = JLabel("Input1: ") lbl1.setBounds(60, 20, 60, 20) txt1 = JTextField(100) txt1.setBounds(130, 20, 200, 20) lbl2 = JLabel("Input2: ") lbl2.setBounds(60, 50, 100, 20) txt2 = JTextField(100) txt2.setBounds(130, 50, 200, 20) lbl3 = JLabel("Input3: ") lbl3.setBounds(60, 80, 140, 20) txt3 = JTextField(100) txt3.setBounds(130, 80, 200, 20) lbl4 = JLabel("Input4: ") lbl4.setBounds(60, 110, 180, 20) txt4 = JTextField(100) txt4.setBounds(130, 110, 200, 20) def getValues(event): print "clicked" ScriptVars.setGlobalVar("Input1", str(txt1.getText())) print(ScriptVars.getGlobalVar("Input1")) ScriptVars.setGlobalVar("Input2", str(txt2.getText())) print(ScriptVars.getGlobalVar("Input2")) ScriptVars.setGlobalVar("Input3", str(txt3.getText())) print(ScriptVars.getGlobalVar("Input3")) ScriptVars.setGlobalVar("Input4", str(txt4.getText())) print(ScriptVars.getGlobalVar("Input4")) btn = JButton("Submit", actionPerformed=getValues) btn.setBounds(160, 150, 100, 20) frame.add(lbl1) frame.add(txt1) frame.add(lbl2) frame.add(txt2) frame.add(btn) frame.add(lbl3) frame.add(txt3) frame.add(lbl4) frame.add(txt4) frame.setVisible(True)
def UI(self): """ User interface for LinkedView """ frame = JFrame("LinkedView") frame.setSize(300, 200) frame.setLayout(GridLayout(4, 1)) link_view = JButton("Link Views", actionPerformed=self.linkView) get_ref = JButton("Update Reference Image", actionPerformed=self.getRef) export_view = JButton("Export Views", actionPerformed=self.exportView) crop_ROIs = JButton("Export Cropped ROIs", actionPerformed=self.saveCroppedROIs) frame.add(link_view) frame.add(get_ref) frame.add(export_view) frame.add(crop_ROIs) frame.setVisible(True)
def showLoginIdPassword(data): global frame frame = JFrame("Show Id Password ") frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) frame.setSize(500,350) frame.setLocation(200,200) frame.setLayout(None) frame.setVisible(True) panel = JPanel() panel.setSize(500,350) panel.setLocation(0,0) panel.setLayout(None) panel.setVisible(True) panel.setBackground(Color.LIGHT_GRAY) heading = JLabel("LoginId AND Password") heading.setBounds(200,30,150,40) lbLoginId = JLabel("LoginId") lbPassword = JLabel("password") tfLoginId = JTextField(data[0].encode('ascii')) tfPassword = JTextField(data[1].encode('ascii')) tfLoginId.setEditable(False) tfPassword.setEditable(False) lbLoginId.setBounds(50,100,150,30) lbPassword.setBounds(50,150,150,30) tfLoginId.setBounds(220,100,150,30) tfPassword.setBounds(220,150,150,30) btnOk = JButton("Ok",actionPerformed=clickOk) btnOk.setBounds(250,220,100,30) panel.add(heading) panel.add(lbLoginId) panel.add(lbPassword) panel.add(tfLoginId) panel.add(tfPassword) panel.add(btnOk) frame.add(panel)
def gui(self): # Hilfsfunktion für event # erstellt ein Rezeptobjekt anhand einer URL # schließt die GUI def create(event): url = field.getText() self.recipe = Recipe(url) frame.dispose() print("created recipe for " + self.recipe.get_title()) # der Dialog wartet, bis "continue" gesendet wird self.send("continue") # Frame erstellen frame = JFrame( 'URL eingeben', defaultCloseOperation=JFrame.EXIT_ON_CLOSE, size=(480, 200), ) frame.setLayout(None) # Text im Frame fieldlabel = JLabel() fieldlabel.setText( "<html><font size=+1>Geben Sie die Internetadresse des Rezepts ein</font></html>" ) fieldlabel.setBounds(20, 20, 500, 40) frame.add(fieldlabel) # Textfeld im Frame field = JTextField() field.setText("https://www.chefkoch.de/rezepte/...") field.setBounds(20, 60, 411, 40) frame.add(field) # Button im Frame # ruft Hilfsfunktion create auf button = JButton("Los!", actionPerformed=create) button.setBounds(155, 100, 150, 30) frame.add(button) #Frame anzeigen frame.setVisible(True)
def getCourseName(check): global frame global tfStudentCourseChoice global value value = check frame = JFrame("Course Name ") frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) frame.setSize(500,250) frame.setLocation(200,200) frame.setLayout(None) frame.setVisible(True) panel = JPanel() panel.setSize(500,250) panel.setLocation(0,0) panel.setLayout(None) panel.setVisible(True) panel.setBackground(Color.LIGHT_GRAY) heading = JLabel("Get Course Name") heading.setBounds(200,30,150,40) lbStudentCourseChoice = JLabel("Student course name") tfStudentCourseChoice = JTextField() lbStudentCourseChoice.setBounds(50,70,150,30) tfStudentCourseChoice.setBounds(220,70,150,30) btnEnter = JButton("Enter",actionPerformed=clickStudentCourseChoice) btnCancel = JButton("Cancel",actionPerformed=clickBtnCancel) btnEnter.setBounds(350,150,100,30) btnCancel.setBounds(50,150,100,30) panel.add(heading) panel.add(lbStudentCourseChoice) panel.add(tfStudentCourseChoice) panel.add(btnEnter) panel.add(btnCancel) frame.add(panel)
def createAndShowGUI(): # Create the GUI and show it. As with all GUI code, this must run # on the event-dispatching thread. frame = JFrame("GUI Development ") frame.setSize(500, 600) frame.setLayout(BorderLayout()) splitPane = JSplitPane(JSplitPane.VERTICAL_SPLIT) #Create and set up the content pane. psimures= ResourcePanel() psimures.setOpaque(True) pconfig = ConfigurationPanel() pconfig.setOpaque(True) #content panes must be opaque # show the GUI splitPane.add(psimures) splitPane.add(pconfig) frame.add(splitPane) frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE) frame.setVisible(True)
def showStudentAttendenceSheetTeacherLogin(): global table global heading global frame global panel global btnSave global btnCancel frame = JFrame("Student Attendence Sheet ") frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) frame.setSize(500,600) frame.setLocation(200,200) frame.setLayout(None) frame.setVisible(True) panel = JPanel() panel.setSize(500,600) panel.setLocation(0,0) panel.setLayout(None) panel.setVisible(True) panel.setBackground(Color.WHITE) heading = JLabel() heading.setBounds(200,10,150,30) table = JTable() table.setBounds(0,50,500,450) panel.add(table) btnSave = JButton("Save",actionPerformed = clickSaveBtn) btnCancel = JButton("Cancel",actionPerformed = clickCancelBtn) btnSave.setBounds(350,540,100,40) btnCancel.setBounds(70,540,100,40) panel.add(heading) panel.add(table) panel.add(btnSave) panel.add(btnCancel) frame.add(panel)
def _initUI(self): frame = JFrame('Simple popup', defaultCloseOperation=JFrame.DISPOSE_ON_CLOSE, size=(300, 300)) frame.setLayout(BoxLayout(frame.contentPane, BoxLayout.PAGE_AXIS)) # Call-back to close popup def closeDialog(event): frame.visible = False frame.dispose() # Instantiate components self.text_area = JTextArea() msgScroller = JScrollPane() msgScroller.setBorder(BorderFactory.createTitledBorder("Accounts")) msgScroller.setViewportView(self.text_area) self.close_button = JButton('Close', actionPerformed=closeDialog) # Add components to frame frame.add(msgScroller) frame.add(self.close_button) frame.visible = True
def __init__(self): frame = JFrame("Jython JTable Example") frame.setSize(500, 250) frame.setLayout(BorderLayout()) self.tableData = [ ['Mouse 1', eventNames[0], eventScriptType[0]], ['Mouse 2', eventNames[1], eventScriptType[1]], ['Mouse 3', eventNames[2], eventScriptType[2]], ['Mouse 1 Shift', eventNames[3], eventScriptType[3]], ['Mouse 2 Shift', eventNames[4], eventScriptType[4]], ['Mouse 3 Shift', eventNames[5], eventScriptType[5]], ['Mouse 1 Control', eventNames[6], eventScriptType[6]], ['Mouse 2 Control', eventNames[7], eventScriptType[7]], ['Mouse 3 Control', eventNames[8], eventScriptType[8]], ] colNames = ('Script/Event', 'Name', 'Type') dataModel = DefaultTableModel(self.tableData, colNames) self.table = JTable(dataModel) scrollPane = JScrollPane() scrollPane.setPreferredSize(Dimension(400, 200)) scrollPane.getViewport().setView((self.table)) panel = JPanel() panel.add(scrollPane) frame.add(panel, BorderLayout.CENTER) self.label = JLabel('Hello from Jython') frame.add(self.label, BorderLayout.NORTH) button = JButton('Save Settings', actionPerformed=self.setText) frame.add(button, BorderLayout.SOUTH) exitButton = JButton('Exit', actionPerformed=self.myExit) frame.add(exitButton, BorderLayout.EAST) frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE) frame.setVisible(True)
def __init__(self): frame = JFrame("Jython JTable Example") frame.setSize(500, 250) frame.setLayout(BorderLayout()) self.tableData = [ ['Mouse 1', eventNames[0], eventScriptType[0]], ['Mouse 2', eventNames[1] , eventScriptType[1]], ['Mouse 3', eventNames[2], eventScriptType[2]], ['Mouse 1 Shift', eventNames[3], eventScriptType[3]], ['Mouse 2 Shift',eventNames[4], eventScriptType[4]], ['Mouse 3 Shift',eventNames[5], eventScriptType[5]], ['Mouse 1 Control',eventNames[6], eventScriptType[6]], ['Mouse 2 Control',eventNames[7], eventScriptType[7]], ['Mouse 3 Control',eventNames[8], eventScriptType[8]], ] colNames = ('Script/Event','Name','Type') dataModel = DefaultTableModel(self.tableData, colNames) self.table = JTable(dataModel) scrollPane = JScrollPane() scrollPane.setPreferredSize(Dimension(400,200)) scrollPane.getViewport().setView((self.table)) panel = JPanel() panel.add(scrollPane) frame.add(panel, BorderLayout.CENTER) self.label = JLabel('Hello from Jython') frame.add(self.label, BorderLayout.NORTH) button = JButton('Save Settings',actionPerformed=self.setText) frame.add(button, BorderLayout.SOUTH) exitButton = JButton('Exit',actionPerformed=self.myExit) frame.add(exitButton, BorderLayout.EAST) frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE) frame.setVisible(True)
def addDetails(self): jf0 = JFrame() jf0.setTitle("Add Issue"); jf0.setLayout(None); txtEnterIssue = JTextField(); txtEnterIssue.setName("Enter Issue Name"); txtEnterIssue.setToolTipText("Enter Issue Name Here"); txtEnterIssue.setBounds(182, 58, 473, 40); jf0.add(txtEnterIssue); txtEnterIssue.setColumns(10); btnNewButton = JButton("Add"); btnNewButton.setBounds(322, 178, 139, 41); jf0.add(btnNewButton); comboBox = JComboBox(); comboBox.setMaximumRowCount(20); comboBox.setEditable(True); comboBox.setToolTipText("Objective Name"); comboBox.setBounds(182, 125, 473, 40); jf0.add(comboBox); lblNewLabel = JLabel("Issue Name Here"); lblNewLabel.setFont(Font("Tahoma", Font.PLAIN, 16)); lblNewLabel.setBounds(25, 58, 130, 40); jf0.add(lblNewLabel); lblNewLabel_1 = JLabel("Objective Name"); lblNewLabel_1.setFont(Font("Tahoma", Font.PLAIN, 16)); lblNewLabel_1.setBounds(25, 125, 130, 40); jf0.add(lblNewLabel_1); jf0.setVisible(True) jf0.setBounds(400, 300, 700, 300) jf0.EXIT_ON_CLOSE txtEnterIssue.addKeyListener(self)
def createStudentFeeForm(stFeeObj): global tfStudentId global tfStudentName global tfTotalAmount global tfPaidAmount global tfRemainingAmount global frame frame = JFrame("Student Fee Form ") frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) frame.setSize(500,500) frame.setLocation(200,200) frame.setLayout(None) frame.setVisible(True) panel = JPanel() panel.setSize(500,500) panel.setLocation(0,0) panel.setLayout(None) panel.setVisible(True) panel.setBackground(Color.LIGHT_GRAY) heading = JLabel("STUDENT FEE") heading.setBounds(200,30,150,40) lbStudentId = JLabel(" Student id") lbStudentName = JLabel(" student name") lbTotalAmount = JLabel("Total Amount ") lbPaidAmount = JLabel("Paid Amount") lbRemainingAmount = JLabel("Remaining amount") studentId =getattr(stFeeObj,'studentId') studentName =getattr(stFeeObj,'studentName') totalAmount =getattr(stFeeObj,'totalAmount') paidAmount =getattr(stFeeObj,'paidAmount') remainingAmount =getattr(stFeeObj,'remainingAmount') tfStudentId = JTextField(str(studentId)) tfStudentName = JTextField(str(studentName)) tfTotalAmount = JTextField(str(totalAmount)) tfPaidAmount = JTextField(str(paidAmount)) tfRemainingAmount = JTextField(str(remainingAmount)) tfStudentId.setEditable(False) tfStudentName.setEditable(False) tfTotalAmount.setEditable(False) tfRemainingAmount.setEditable(False) lbStudentId.setBounds(70,100,130,30) lbStudentName.setBounds(70,150,130,30) lbTotalAmount.setBounds(70,200,130,30) lbPaidAmount.setBounds(70,250,130,30) lbRemainingAmount.setBounds(70,300,130,30) tfStudentId.setBounds(220,100,130,30) tfStudentName.setBounds(220,150,130,30) tfTotalAmount.setBounds(220,200,130,30) tfPaidAmount.setBounds(220,250,130,30) tfRemainingAmount.setBounds(220,300,130,30) btnPay = JButton("Paid",actionPerformed=clickPay) btnPay.setBounds(350,410,100,40) btnCancel = JButton("Cancel",actionPerformed=clickbtnCancelForm) btnCancel.setBounds(50,410,100,40) panel.add(heading) panel.add(lbStudentId) panel.add(lbStudentName) panel.add(lbTotalAmount) panel.add(lbPaidAmount) panel.add(lbRemainingAmount) panel.add(tfStudentId) panel.add(tfStudentName) panel.add(tfTotalAmount) panel.add(tfPaidAmount) panel.add(tfRemainingAmount) panel.add(btnPay) panel.add(btnCancel) frame.add(panel)
def output(self, value): eingabe = value.getString() if eingabe == "Lexikon": # Falls "Lexikon" an den Clienten übergeben wird, wird die GUI geöffnet, # in der man deutsche Wörter eingeben kann, die einem dann auf Englisch # vorgelesen werden. def change_text(event): text = feld.getText() x = suche(text) self.send(x) frame.visible = False frame = JFrame( 'Woerterbuch', defaultCloseOperation=JFrame.EXIT_ON_CLOSE, size=(380, 350), ) frame.setLayout(None) frame.visible = True hintergrund = ImageIcon("Hintergrund.jpg") hintergrundlabel = JLabel(hintergrund) frame.setContentPane(hintergrundlabel) uebersetzerlabel = JLabel() uebersetzerlabel.setForeground(Color(025, 025, 112)) uebersetzerlabel.setText( "<html><font size=+1>Welches Wort soll ich uebersetzen?</font></html>" ) uebersetzerlabel.setBounds(10, 20, 500, 50) frame.add(uebersetzerlabel) feld = JTextField() feld.setText("") feld.setBounds(20, 80, 300, 25) frame.add(feld) button = JButton('Uebersetzen', actionPerformed=change_text, size=(10, 20)) button.setBounds(20, 110, 300, 30) frame.add(button) if eingabe == "neue Lektion": # Falls dem Clienten "neue Lektion" übergeben wird, öffnet er er die # GUI für das Verwalten der Lektionen frame = JFrame('Lektion erstellen', defaultCloseOperation=JFrame.EXIT_ON_CLOSE, size=(1000, 1000)) frame.setLayout(None) def auflisten_in(ort): font = Font("Verdana", Font.BOLD, 15) liste_mit_Lektionen = [] with open(pfad, "r") as f: for line in f: liste_mit_Lektionen.append(line.strip()) liste_mit_Lektionen.sort() text = "" for lektion in liste_mit_Lektionen: text += lektion text += "\n" ort.setText(text) ort.setFont(font) frame.setLayout(None) uebersichtLabel = JLabel() def uebersetzen(event): frage = feld_frage.getText() x = suche(frage) feld_frage.setText(x) liste = [] with open(pfad, "r") as lektionen: for lektion in lektionen: if "nachgeschlagen" in lektion: liste.append(lektion) if liste: name = liste[-1] words = [] sql = "SELECT deutsch, englisch, symbol FROM " + name zeile = stmt.executeQuery(sql) while zeile.next(): d = zeile.getString("deutsch") e = zeile.getString("englisch") symb = zeile.getString("symbol") words.append((d, e, symb)) if len(words) < 50: sql = "INSERT INTO " + name + " (deutsch, englisch, symbol) VALUES(?,?,?);" pstmt = conn.prepareStatement(sql) pstmt.setString(1, frage) pstmt.setString(2, x) pstmt.setString(3, "X") pstmt.executeUpdate() else: namensteile = name.split("_") nummer = int(namensteile[1].strip()) + 1 name = "nachgeschlagen_" + str(nummer) test = "" with open(pfad, "r") as f: for line in f: test += line if not name in test: with open(pfad, "a") as f: f.write(name + "\n") sql = "CREATE TABLE " + name + " (deutsch text, englisch text, symbol text);" stmt.execute(sql) sql = "INSERT INTO " + name + " (deutsch, englisch, symbol) VALUES(?,?,?);" pstmt = conn.prepareStatement(sql) pstmt.setString(1, frage) pstmt.setString(2, x) pstmt.setString(3, "X") pstmt.executeUpdate() else: name = "nachgeschlagen_1" test = "" with open(pfad, "r") as f: for line in f: test += line if not name in test: with open(pfad, "a") as f: f.write(name + "\n") sql = "CREATE TABLE " + name + " (deutsch text, englisch text, symbol text);" stmt.execute(sql) sql = "INSERT INTO " + name + " (deutsch, englisch, symbol) VALUES(?,?,?);" pstmt = conn.prepareStatement(sql) pstmt.setString(1, frage) pstmt.setString(2, x) pstmt.setString(3, "X") pstmt.executeUpdate() auflisten_in(uebersicht) def delete(event): name = feld.getText() print name print self.geladen if name == self.geladen: count = 0 while tabelle.getValueAt(count, 0) != None: tabelle.setValueAt(None, count, 0) tabelle.setValueAt(None, count, 1) count += 1 stmt.execute("DROP TABLE " + name + ";") lektionen = [] with open(pfad, "r") as f: for line in f: lektion = line.strip() if not name == lektion: lektionen.append(lektion) with open(pfad, "w") as f: for lektion in lektionen: f.write(lektion + "\n") auflisten_in(uebersicht) def laden(event): name = feld.getText() self.geladen = name sql = "SELECT deutsch, englisch FROM " + name results = stmt.executeQuery(sql) count = 0 while results.next(): d = results.getString("deutsch") e = results.getString("englisch") tabelle.setValueAt(d, count, 0) tabelle.setValueAt(e, count, 1) count += 1 while tabelle.getValueAt(count, 0) != None: tabelle.setValueAt(None, count, 0) tabelle.setValueAt(None, count, 1) count += 1 def erstelle_Lektionstabelle(event): reihen = [] for i in range(0, 50): deutsch = tabelle.getValueAt(i, 0) englisch = tabelle.getValueAt(i, 1) if deutsch != None: symbol = "X" reihen.append([deutsch, englisch, symbol]) else: break z = 0 name = feld.getText() sql = "CREATE TABLE " + name + " (deutsch text, englisch text, symbol text);" try: stmt.execute(sql) except SQLError: stmt.execute("DROP TABLE " + name + ";") stmt.execute(sql) for reihe in reihen: print(reihe) deutsch = reihe[0] englisch = reihe[1] symbol = reihe[2] sql = "INSERT INTO " + name + " (deutsch, englisch, symbol) VALUES(?,?,?);" pstmt = conn.prepareStatement(sql) pstmt.setString(1, deutsch) pstmt.setString(2, englisch) pstmt.setString(3, symbol) pstmt.executeUpdate() test = "" with open(pfad, "r") as f: for line in f: test += line if not name in test: with open(pfad, "a") as f: f.write(name + "\n") self.send(name) frame.setVisible(False) frame = JFrame('Vokabel Listen', defaultCloseOperation=JFrame.EXIT_ON_CLOSE, size=(1000, 1000)) frame.setLayout(None) label_enter = JLabel() label_enter.setText( "<html><font size=+0.5 color = 000000>Bitte vor dem Speichern<br>die Entertaste bedienen</font></html>" ) label_enter.setBounds(20, 720, 250, 50) uebersichtLabel = JLabel() uebersichtLabel.setText( "<html><font size=+1 color=#191970>Bereits vorhandene Lektionen:</font></html>" ) uebersichtLabel.setBounds(450, 230, 250, 50) uebersicht = JTextArea() uebersicht.editable = False uebersicht_scroll = JScrollPane(uebersicht) uebersicht_scroll.viewport.view = uebersicht uebersicht_scroll.setBounds(450, 300, 250, 380) auflisten_in(uebersicht) button = JButton('Lektion speichern/Lektion reseten', actionPerformed=erstelle_Lektionstabelle, size=(10, 20)) button.setBounds(20, 700, 300, 30) button_laden = JButton('vorhandene Lektion laden', actionPerformed=laden, size=(10, 20)) button_laden.setBounds(20, 110, 210, 30) button_delete = JButton("Lektion entfernen", actionPerformed=delete) button_delete.setBounds(20, 140, 210, 30) hintergrund = ImageIcon("Hintergrund.jpg") pnl = JPanel() hintergrundlabel = JLabel(hintergrund) frame.setContentPane(hintergrundlabel) lektionsnamensLabel = JLabel() lektionsnamensLabel.setForeground(Color(025, 025, 112)) lektionsnamensLabel.setText( "<html><font size=+1>Hier bitte Namen der Lektion eingeben<br>(Nur ein Wort lang)</font></html>" ) lektionsnamensLabel.setBounds(10, 20, 500, 50) frame.add(lektionsnamensLabel) feld = JTextField() feld.setText("") feld.setBounds(20, 80, 210, 25) frame.add(feld) column_names = [ "<html><font size=+1 color=#191970><b>Deutsch</b></font></html>", "<html><font size=+1 color=#191970><b>Englisch</b></font></html>" ] table_model = DefaultTableModel(column_names, 50) tabelle = JTable(table_model) lektionsnamensLabel.setForeground(Color(025, 025, 112)) scrollbar = JScrollPane(tabelle) scrollbar.viewport.view = tabelle scrollbar.setVerticalScrollBarPolicy( scrollbar.VERTICAL_SCROLLBAR_ALWAYS) scrollbar.setVisible(True) tabelle.setVisible(True) scrollbar.setBounds(20, 190, 300, 490) feld_frage = JTextField() feld_frage.setText("") feld_frage.setBounds(450, 30, 300, 50) uebersetzerlabel = JLabel() uebersetzerlabel.setForeground(Color(025, 025, 112)) uebersetzerlabel.setText( "<html><font size=+1>Hier kannst Du ein deutsches Wort eintragen,<br>dass ich fuer Dich nachschlage</font></html>" ) uebersetzerlabel.setBounds(450, 80, 500, 50) button_uebersetzen = JButton('Uebersetzen', actionPerformed=uebersetzen, size=(10, 20)) button_uebersetzen.setBounds(450, 130, 300, 30) frame.add(button_uebersetzen) frame.add(uebersetzerlabel) frame.add(feld_frage) frame.add(feld) frame.add(scrollbar) frame.add(button) frame.add(button_laden) frame.setVisible(True) frame.add(uebersicht_scroll) frame.add(uebersichtLabel) frame.add(button_delete) frame.add(label_enter) elif eingabe == "alle Lektionen auflisten": # Hier erstellt der Client eine dynamische Grammatik # mit den vorhandenen Lektionen, die man sich abfragen lassen kann # und gibt diese wieder an DialogOS zurück. # Außerdem wird der Feedback Frame geöffnet. def auflisten_in2(ort): font = Font("Verdana", Font.BOLD, 15) liste_mit_Lektionen = [] with open(pfad, "r") as f: for line in f: liste_mit_Lektionen.append(line.strip()) liste_mit_Lektionen.sort() text = "" for lektion in liste_mit_Lektionen: text += lektion text += "\n" ort.setText(text) ort.setFont(font) frame_feedback.setVisible(True) auflisten_in2(uebersicht2) grammatik = "" grammatik = "root $NamevonLektion;\n" grammatik += "$NamevonLektion = " with open(pfad, "r") as f: z = 0 for line in f: if z == 0: if not "_" in line: grammatik += line else: zeile = line.split("_") grammatik += zeile[0] + " " grammatik += zeile[1].strip() else: if not "_" in line: grammatik += "|" + line else: zeile = line.split("_") grammatik += "|" + zeile[0] + " " grammatik += zeile[1].strip() if line != "\n": z += 1 grammatik += ";" self.send(grammatik) elif "sende" in eingabe: # DialogOS sagt dem Clienten, welche Lektion der User abgefragt # werden möchte. Der Client ließt dann die entsprechende Lektion # aus der Datenbank aus und gibt eine Liste mit 2 Listen zurück. # In der ersten Liste befinden sich die deutschen Bedeutungen, der # noch nicht gewussten Wörter, in der 2. Liste die englsichen Bedeutungen. # Falls alle Wörter bereits gekonnt wurden, wird stattdessen eine entsprechende # Anmerkung an DialogOS geschickt und DialogOS informiert den User darüber. z = 0 if "nachgeschlagen" in eingabe: bestandteile = eingabe.split() name = bestandteile[1] + "_" + bestandteile[2] else: name = eingabe.split()[1] sql = "SELECT deutsch, englisch, symbol FROM " + name vokabelliste = stmt.executeQuery(sql) deutsch = [] englisch = [] symbol = [] while (vokabelliste.next()): deutsch.append(vokabelliste.getString("deutsch")) englisch.append(vokabelliste.getString("englisch")) symbol.append(vokabelliste.getString("symbol")) indices = range(0, len(deutsch)) random.shuffle(indices) vokabeln = [[], []] for index in indices: d = deutsch[index] e = englisch[index] s = symbol[index] if s == "X": vokabeln[0].append(d) vokabeln[1].append(e) if vokabeln[0]: self.send(vokabeln) else: self.send([ "Du kannst diese Lektion schon komplett. Wenn Du sie wieder abgefragt werden willst, resete sie bitte unter Wokabeln verwalten." ]) else: # Dieser Teil des Codes wird während der Abfrage ausgeführt. # Nach jeder neuen Vokabel wird dann in ein Feld im Feedback # Frame die deutsche, die englische Vokabel und ein Symbol angezeigt, # welches einen darüber informiert, ob man die Vokabel wusste, oder nicht. # (O für gewusst und X für nicht gewusst) nametext = eingabe.split(":") name = nametext[0] text = nametext[1] feld_feedback.setText(text) zeilen = text.split("\n") symb = zeilen[-2].split("\t")[-1] d = zeilen[-2].split("\t")[-3] print d sql = "UPDATE " + name + " SET symbol = ? WHERE deutsch = ?" pstmt = conn.prepareStatement(sql) pstmt.setString(1, symb) pstmt.setString(2, d) pstmt.executeUpdate()
conn = DriverManager.getConnection(url) stmt = conn.createStatement() pfad = "C:/Users/marc_/Desktop/Dialogsysteme/Vokabeltrainer/VokTrainer2/Vokabeltrainer2/jython-demo-client-master/jython-demo-client-master_neueLektion/Lektionen/alleLektionen" import random #Feedback Frame für die Abfrage # Wird später sichtbar gemacht def close2(event): frame_feedback.setVisible(False) frame_feedback = JFrame('Abfrage', defaultCloseOperation=JFrame.EXIT_ON_CLOSE, size=(1000, 1000)) frame_feedback.setLayout(None) uebersichtLabel2 = JLabel() uebersichtLabel2.setText( "<html><font size=+1 color=#191970>vorhandene Lektionen:</font></html>") uebersichtLabel2.setBounds(450, 200, 250, 50) uebersicht2 = JTextArea() uebersicht2.editable = False uebersicht_scroll2 = JScrollPane(uebersicht2) uebersicht_scroll2.viewport.view = uebersicht2 uebersicht_scroll2.setBounds(450, 250, 250, 410) feld_feedback = JTextArea() feld_feedback.editable = False feld_feedback.setBounds(50, 50, 300, 600) button_close = JButton('close window', actionPerformed=close2) button_close.setBounds(50, 650, 300, 30) hintergrund2 = ImageIcon("Hintergrund.jpg")
def guiFrame(self): frame = JFrame("PyNews") frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) frame.setLocationRelativeTo(None) frame.setSize(600, 200) frame.setResizable(False) frame.setLayout(GridLayout(5, 3, 10, 10)) # logo self.logo = JLabel(" PyNews") # query input self.input_field = JTextField(30) # search button self.src_button = JButton("Search!", actionPerformed=self.pyNewsSearch) # expand button self.exp_button = JButton("Expand!", actionPerformed=self.expandNews) self.exp_button.setEnabled(False) # open button self.opn_button = JButton("Open!", actionPerformed=self.openNews) self.opn_button.setEnabled(False) # open html button self.htm_button = JButton("HTML-Open!", actionPerformed=self.openHTML) self.htm_button.setEnabled(False) # write to file button self.wrt_button = JButton("CSV-Write!", actionPerformed=self.writeToCSV) self.wrt_button.setEnabled(False) # checkboxes self.categories = [ "authors", "publish_date", "top_image", "movies", "text", "article_html", "summary", "keywords" ] self.checkboxes = [] for cat in self.categories: self.checkboxes.append(JCheckBox(cat)) # add to frame frame.add(self.logo) frame.add(self.input_field) frame.add(self.src_button) frame.add(self.exp_button) for cb in self.checkboxes[:2]: frame.add(cb) frame.add(self.opn_button) for cb in self.checkboxes[2:4]: frame.add(cb) frame.add(self.htm_button) for cb in self.checkboxes[4:6]: frame.add(cb) frame.add(self.wrt_button) for cb in self.checkboxes[6:8]: frame.add(cb) print("got to end ") frame.setVisible(True)
class MandersPlugin(ImageListener, WindowAdapter): def __init__(self): self.imp = None self.preview = None self.createMainWindow() self.cells = None self.files = [] self.results = ResultsTable() ImagePlus.addImageListener(self) self.selectInputDir() self.selectOutputDir() self.pairs = [] self.methods = [] self.processNextFile() def selectInputDir(self): inputDialog = DirectoryChooser("Please select a directory contaning your images") inputDir = inputDialog.getDirectory() for imageFile in os.listdir(inputDir): self.files.append(inputDir + imageFile) def selectOutputDir(self): outputDialog = DirectoryChooser("Please select a directory to save your results") self.outputDir = outputDialog.getDirectory() def closeImage(self): if self.imp is not None: self.imp.close() self.imp = None if self.preview is not None: self.preview.close() self.preview = None def openImage(self, imageFile): try: images = BF.openImagePlus(imageFile) self.imp = images[0] except UnknownFormatException: return None if self.imp.getNChannels() < 2: IJ.error("Bad image format", "Image must contain at lease 2 channels!") return None if not self.pairs or \ not self.methods: self.getOptionsDialog(self.imp) title = self.imp.title self.imp.title = title[:title.rfind('.')] return self.imp def getOptionsDialog(self, imp): thr_methods = ["None", "Default", "Huang", "Intermodes", "IsoData", "Li", "MaxEntropy","Mean", "MinError(I)", "Minimum", "Moments", "Otsu", "Percentile", "RenyiEntropy", "Shanbhag" , "Triangle", "Yen"] gd = GenericDialog("Please select channels to collocalize") for i in range(1, imp.getNChannels() + 1): gd.addChoice("Threshold method for channel %i" % i, thr_methods, "None") gd.showDialog() if gd.wasCanceled(): self.exit() channels = [] for i in range(1, imp.getNChannels() + 1): method = gd.getNextChoice() self.methods.append(method) if method != "None": channels.append(i) for x in channels: for y in channels: if x < y: self.pairs.append((x, y)) def processNextFile(self): if self.files: imageFile = self.files.pop(0) return self.processFile(imageFile) else: return False def processFile(self, imageFile): imp = self.openImage(imageFile) if imp is not None: cell = Cell(imp.NSlices, 1) self.cells = DelegateListModel([]) self.cells.append(cell) self.showMainWindow(self.cells) if self.checkbox3D.isSelected(): self.displayImage(imp) else: self.displayImage(imp, False) self.preview = self.previewImage(imp) self.displayImage(self.preview) return True else: return self.processNextFile() def displayImage(self, imp, show = True): imp.setDisplayMode(IJ.COMPOSITE) enhancer = ContrastEnhancer() enhancer.setUseStackHistogram(True) splitter = ChannelSplitter() for c in range(1, imp.getNChannels() + 1): imp.c = c enhancer.stretchHistogram(imp, 0.35) if show: imp.show() def previewImage(self, imp): roi = imp.getRoi() splitter = ChannelSplitter() channels = [] for c in range(1, imp.getNChannels() + 1): channel = ImagePlus("Channel %i" % c, splitter.getChannel(imp, c)) projector = ZProjector(channel) projector.setMethod(ZProjector.MAX_METHOD) projector.doProjection() channels.append(projector.getProjection()) image = RGBStackMerge.mergeChannels(channels, False) image.title = imp.title + " MAX Intensity" image.luts = imp.luts imp.setRoi(roi) return image def getCroppedChannels(self, imp, cell): splitter = ChannelSplitter() imp.setRoi(None) if cell.mode3D: cropRoi = cell.getCropRoi() else: cropRoi = cell.roi if cropRoi is None: return None crop = cropRoi.getBounds() channels = [] for c in range(1, imp.getNChannels() + 1): slices = ImageStack(crop.width, crop.height) channel = splitter.getChannel(imp, c) for z in range(1, channel.getSize() + 1): zslice = channel.getProcessor(z) zslice.setRoi(cropRoi) nslice = zslice.crop() if cell.mode3D: oroi = cell.slices[z - 1].roi else: oroi = cell.roi if oroi is not None: roi = oroi.clone() bounds = roi.getBounds() roi.setLocation(bounds.x - crop.x, bounds.y - crop.y) nslice.setColor(Color.black) nslice.fillOutside(roi) slices.addSlice(nslice) channels.append(ImagePlus("Channel %i" % c, slices)) return channels def getThreshold(self, imp, method): thresholder = Auto_Threshold() duplicator = Duplicator() tmp = duplicator.run(imp) return thresholder.exec(tmp, method, False, False, True, False, False, True) def getContainer(self, impA, impB): imgA = ImagePlusAdapter.wrap(impA) imgB = ImagePlusAdapter.wrap(impB) return DataContainer(imgA, imgB, 1, 1, "imageA", "imageB") def getManders(self, imp, cell): ### Crop channels according to cell mask channels = self.getCroppedChannels(imp, cell) if channels is None: return None ### Calculate channel thresholds thrs = [] thrimps = [] for c, method in enumerate(self.methods): if method != "None": thr, thrimp = self.getThreshold(channels[c], method) else: thr, thrimp = None, None thrs.append(thr) thrimps.append(thrimp) ### Calculate manders colocalization manders = MandersColocalization() raws = [] thrds = [] for chA, chB in self.pairs: container = self.getContainer(channels[chA - 1], channels[chB - 1]) img1 = container.getSourceImage1() img2 = container.getSourceImage2() mask = container.getMask() cursor = TwinCursor(img1.randomAccess(), img2.randomAccess(), Views.iterable(mask).localizingCursor()) rtype = img1.randomAccess().get().createVariable() raw = manders.calculateMandersCorrelation(cursor, rtype) rthr1 = rtype.copy() rthr2 = rtype.copy() rthr1.set(thrs[chA - 1]) rthr2.set(thrs[chB - 1]) cursor.reset() thrd = manders.calculateMandersCorrelation(cursor, rthr1, rthr2, ThresholdMode.Above) raws.append(raw) thrds.append(thrd) return (channels, thrimps, thrs, raws, thrds) def saveMultichannelImage(self, title, channels, luts): tmp = RGBStackMerge.mergeChannels(channels, False) tmp.luts = luts saver = FileSaver(tmp) saver.saveAsTiffStack(self.outputDir + title + ".tif") tmp.close() def createMainWindow(self): self.frame = JFrame('Select cells and ROIs', defaultCloseOperation = JFrame.DISPOSE_ON_CLOSE ) self.frame.setLayout(GridBagLayout()) self.frame.addWindowListener(self) self.frame.add(JLabel("Cells"), GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, Insets(5, 2, 2, 0), 0, 0 )) self.cellList = JList(DelegateListModel([]), selectionMode = ListSelectionModel.SINGLE_SELECTION, cellRenderer = MyRenderer(), selectedIndex = 0, valueChanged = self.selectCell ) self.frame.add(JScrollPane(self.cellList), GridBagConstraints(0, 1, 1, 5, .5, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, Insets(0, 2, 2, 0), 0, 0 )) self.frame.add(JButton('Add cell', actionPerformed = self.addCell), GridBagConstraints(1, 2, 1, 2, 0, .25, GridBagConstraints.CENTER, GridBagConstraints.NONE, Insets(0, 0, 0, 0), 0, 0 )) self.frame.add(JButton('Remove cell', actionPerformed = self.removeCell), GridBagConstraints(1, 4, 1, 2, 0, .25, GridBagConstraints.CENTER, GridBagConstraints.NONE, Insets(0, 5, 0, 5), 0, 0 )) self.frame.add(JLabel("Slices"), GridBagConstraints(0, 6, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, Insets(5, 2, 2, 0), 0, 0 )) self.sliceList = JList(DelegateListModel([]), selectionMode = ListSelectionModel.SINGLE_SELECTION, cellRenderer = MyRenderer(), selectedIndex = 0, valueChanged = self.selectSlice ) self.frame.add(JScrollPane(self.sliceList), GridBagConstraints(0, 7, 1, 5, .5, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, Insets(0, 2, 2, 0), 0, 0 )) self.frame.add(JButton('Update ROI', actionPerformed = self.updateSlice), GridBagConstraints(1, 8, 1, 2, 0, .25, GridBagConstraints.CENTER, GridBagConstraints.NONE, Insets(0, 0, 0, 0), 0, 0 )) self.frame.add(JButton('Done', actionPerformed = self.doneSelecting), GridBagConstraints(1, 10, 1, 2, 0, .25, GridBagConstraints.CENTER, GridBagConstraints.NONE, Insets(0, 0, 0, 0), 0, 0 )) self.checkbox3D = JCheckBox('3D selection mode', True, actionPerformed=self.toggle3D) self.frame.add(self.checkbox3D, GridBagConstraints(0, 13, 2, 1, 0, 1, GridBagConstraints.WEST, GridBagConstraints.NONE, Insets(0, 0, 0, 0), 0, 0 )) def showMainWindow(self, cells = None): if cells is not None: self.cellList.model = cells if cells: self.cellList.selectedIndex = 0 self.frame.pack() self.frame.visible = True def hideMainWindow(self): self.frame.visible = False def closeMainWindow(self): self.frame.dispose() def toggle3D(self, event): mode3D = self.checkbox3D.isSelected() if mode3D: self.sliceList.enabled = True if self.imp is not None: self.imp.show() if self.preview is not None: self.preview.hide() else: self.sliceList.enabled = False if self.preview is None: self.preview = self.previewImage(self.imp) self.displayImage(self.preview) else: self.preview.show() if self.imp is not None: self.imp.hide() selectedCell = self.cellList.selectedIndex if selectedCell >= 0: cell = self.cells[selectedCell] self.sliceList.model = cell.slices self.sliceList.selectedIndex = 0 def addCell(self, event): size = len(self.cells) if (size > 0): last = self.cells[size - 1] n = last.n + 1 else: n = 1 self.cells.append(Cell(self.imp.NSlices, n)) self.cellList.selectedIndex = size def removeCell(self, event): selected = self.cellList.selectedIndex if selected >= 0: self.cells.remove(self.cells[selected]) if (selected >= 1): self.cellList.selectedIndex = selected - 1 else: self.cellList.selectedIndex = 0 def selectCell(self, event): selected = self.cellList.selectedIndex if selected >= 0: cell = self.cells[selected] self.sliceList.model = cell.slices self.sliceList.selectedIndex = 0 else: self.sliceList.model = DelegateListModel([]) if self.preview is not None: self.preview.setRoi(cell.roi) def selectSlice(self, event): selectedCell = self.cellList.selectedIndex selectedSlice = self.sliceList.selectedIndex if selectedCell >= 0 and selectedSlice >= 0: cell = self.cells[selectedCell] image = self.imp mode3D = self.checkbox3D.isSelected() if image is not None and cell is not None and mode3D: roi = cell.slices[selectedSlice].roi if (image.z - 1 != selectedSlice): image.z = selectedSlice + 1 image.setRoi(roi, True) if self.preview is not None and not mode3D: self.preview.setRoi(cell.roi, True) def updateSlice(self, event): if self.checkbox3D.isSelected(): self.updateSlice3D(self.imp) else: self.updateSlice2D(self.preview) def updateSlice3D(self, imp): selectedCell = self.cellList.selectedIndex selectedSlice = self.sliceList.selectedIndex if selectedCell >= 0 and selectedSlice >= 0 and imp is not None: cell = self.cells[selectedCell] impRoi = imp.getRoi() if cell is not None and impRoi is not None: index = selectedSlice + 1 roi = ShapeRoi(impRoi, position = index) cell.mode3D = True cell.name = "Cell %i (3D)" % cell.n cell.slices[selectedSlice].roi = roi if (index + 1 <= len(cell.slices)): imp.z = index + 1 self.cellList.repaint(self.cellList.getCellBounds(selectedCell, selectedCell)) self.sliceList.repaint(self.sliceList.getCellBounds(selectedSlice, selectedSlice)) def updateSlice2D(self, imp): selectedCell = self.cellList.selectedIndex if selectedCell >= 0 and imp is not None: cell = self.cells[selectedCell] impRoi = imp.getRoi() if cell is not None and impRoi is not None: roi = ShapeRoi(impRoi, position = 1) cell.mode3D = False cell.name = "Cell %i (2D)" % cell.n cell.roi = roi self.cellList.repaint(self.cellList.getCellBounds(selectedCell, selectedCell)) def imageOpened(self, imp): pass def imageClosed(self, imp): pass def imageUpdated(self, imp): if self.checkbox3D.isSelected(): if imp is not None: selectedCell = self.cellList.selectedIndex selectedSlice = imp.z - 1 if imp == self.imp and selectedSlice != self.sliceList.selectedIndex: self.sliceList.selectedIndex = selectedSlice def doneSelecting(self, event): oluts = self.imp.luts luts = [] channels = [] for c, method in enumerate(self.methods): if method != "None": luts.append(oluts[c]) channels.append(c) for cell in self.cells: manders = self.getManders(self.imp, cell) if manders is not None: chimps, thrimps, thrs, raws, thrds = manders index = self.cells.index(cell) + 1 title = "Cell_%i-" % index + self.imp.title self.saveMultichannelImage(title, chimps, oluts) title = "Cell_%i_thrd-" % index + self.imp.title self.saveMultichannelImage(title, thrimps, luts) self.results.incrementCounter() row = self.results.getCounter() - 1 for i, thr in enumerate(thrs): if thr is not None: self.results.setValue("Threshold %i" % (i + 1), row, int(thr)) for i, pair in enumerate(self.pairs): self.results.setValue("%i-%i M1 raw" % pair, row, float(raws[i].m1)) self.results.setValue("%i-%i M2 raw" % pair, row, float(raws[i].m2)) self.results.setValue("%i-%i M1 thrd" % pair, row, float(thrds[i].m1)) self.results.setValue("%i-%i M2 thrd" % pair, row, float(thrds[i].m2)) self.closeImage() if not self.processNextFile(): print "All done - happy analysis!" self.results.show("Manders collocalization results") self.exit() def windowClosing(self, e): print "Closing plugin - BYE!!!" self.exit() def exit(self): ImagePlus.removeImageListener(self) self.closeImage() self.closeMainWindow()
class TicTacToeGame(WindowAdapter): # Tic Tac Toe game with Mario and Dizzy animated icons/music. # Computer plays with Mario and player plays with Dizzy. # game title game_title = "Tic Tac Toe: You vs Mario" # welcome status message. welcome_status = "Welcome! Please make your first move." # in-game status message. in_game_status = "Mario chases You! Hurry up!" # board 3x3 with the default color - white board = [[' ', ' ', ' '], [' ', ' ', ' '], [' ', ' ', ' ']] # total number of cells size = len(board) * len(board) # size of cell tile_size = 128 # status bar height status_bar_height = 50 # status bar top margin status_bar_margin_top = -15 # status bar left margin status_bar_margin_left = 10 # number of cells in a row/column cells = 3 # winner winner = None # Mario image mario = '/MARIO_128x128.gif' # Dizzy image dizzy = None # Blank blank = '/BLANK.gif' # supported musice sounds sounds = ['/DIZZY.wav', '/MARIO.wav'] # currently played sound sound = None # last chosen sound last_sound = 0 # won sound won_sound = '/WON.wav' # lose sound lose_sound = '/LOSE.wav' # tie sound tie_sound = '/TIE.wav' # action sound action_sound = '/ACTION.wav' def __init__(self, resources_directory): # Game constructor. # # Parameters: # resources_directory Directory to look for images and audio files. is_windows = platform.platform().lower().find('win') > 0 self.main_window_padding_right = 20 if is_windows else 0 self.main_window_padding_bottom = 40 if is_windows else 0 self.resources_directory = resources_directory self.button1 = JButton("", actionPerformed=self.clicked1) self.button2 = JButton("", actionPerformed=self.clicked2) self.button3 = JButton("", actionPerformed=self.clicked3) self.button4 = JButton("", actionPerformed=self.clicked4) self.button5 = JButton("", actionPerformed=self.clicked5) self.button6 = JButton("", actionPerformed=self.clicked6) self.button7 = JButton("", actionPerformed=self.clicked7) self.button8 = JButton("", actionPerformed=self.clicked8) self.button9 = JButton("", actionPerformed=self.clicked9) image_size = self.tile_size self.button1.setBounds(0 * image_size, 0 * image_size, image_size, image_size) self.button2.setBounds(1 * image_size, 0 * image_size, image_size, image_size) self.button3.setBounds(2 * image_size, 0 * image_size, image_size, image_size) self.button4.setBounds(0 * image_size, 1 * image_size, image_size, image_size) self.button5.setBounds(1 * image_size, 1 * image_size, image_size, image_size) self.button6.setBounds(2 * image_size, 1 * image_size, image_size, image_size) self.button7.setBounds(0 * image_size, 2 * image_size, image_size, image_size) self.button8.setBounds(1 * image_size, 2 * image_size, image_size, image_size) self.button9.setBounds(2 * image_size, 2 * image_size, image_size, image_size) self.buttons = [ self.button1, self.button2, self.button3, self.button4, self.button5, self.button6, self.button7, self.button8, self.button9 ] self.buttons_mapped = [[self.button1, self.button2, self.button3], [self.button4, self.button5, self.button6], [self.button7, self.button8, self.button9]] width = self.tile_size * self.cells height = width self.frame = JFrame(self.game_title, size=(width, height + self.status_bar_height)) self.frame.setLocation(200, 100) self.frame.setLayout(None) for button in self.buttons: self.frame.add(button) self.status_label = JLabel("") self.status_label.setBounds(self.status_bar_margin_left, height + self.status_bar_margin_top, width, self.status_bar_height) self.frame.add(self.status_label) self.frame.setVisible(True) self.frame.addWindowListener(self) random.shuffle(self.sounds) self.restart() # Restarts the game. def restart(self): self.dizzy = None self.dizzy = self.choosePlayer() self.winner = None self.board = [[' ', ' ', ' '], [' ', ' ', ' '], [' ', ' ', ' ']] for button in self.buttons: button.setIcon(ImageIcon(self.resources_directory + self.blank)) self.stop_playing_background() self.sound = self.play_sound_safe(self.sounds[self.last_sound]) self.last_sound = self.last_sound + 1 if self.last_sound >= len(self.sounds): self.last_sound = 0 self.status_label.setText(self.welcome_status) # Stops playing any background music, if any playing now. def stop_playing_background(self): if self.sound != None: self.sound.stopPlaying() self.sound = None def set_dizzy(self, button): # Draws Dizzy in a given button, sets game status to "Playing" and # plays action sound. # # Parameters: # button to set Dizzy icon to. button.setIcon(ImageIcon(self.resources_directory + self.dizzy)) self.status_label.setText(self.in_game_status) self.play_sound_safe(self.action_sound) def set_mario(self, button): # Draws Mario in a given button. # # Parameters: # button to set Mario icon to. button.setIcon(ImageIcon(self.resources_directory + self.mario)) def clicked1(self, event): # Event listener method for the button of the game at 0x0. # # Parameters: # event Click event. if self.board[0][0] != ' ': return self.board[0][0] = 'X' self.set_dizzy(self.button1) self.computer_move() def clicked2(self, event): # Event listener method for the button of the game at 0x1. # # Parameters: # event Click event. if self.board[0][1] != ' ': return self.board[0][1] = 'X' self.set_dizzy(self.button2) self.computer_move() def clicked3(self, event): # Event listener method for the button of the game at 0x2. # # Parameters: # event Click event. if self.board[0][2] != ' ': return self.board[0][2] = 'X' self.set_dizzy(self.button3) self.computer_move() def clicked4(self, event): # Event listener method for the button of the game at 1x0. # # Parameters: # event Click event. if self.board[1][0] != ' ': return self.board[1][0] = 'X' self.set_dizzy(self.button4) self.computer_move() def clicked5(self, event): # Event listener method for the button of the game at 1x1. # # Parameters: # event Click event. if self.board[1][1] != ' ': return self.board[1][1] = 'X' self.set_dizzy(self.button5) self.computer_move() def clicked6(self, event): # Event listener method for the button of the game at 1x2. # # Parameters: # event Click event. if self.board[1][2] != ' ': return self.board[1][2] = 'X' self.set_dizzy(self.button6) self.computer_move() def clicked7(self, event): # Event listener method for the button of the game at 2x0. # # Parameters: # event Click event. if self.board[2][0] != ' ': return self.board[2][0] = 'X' self.set_dizzy(self.button7) self.computer_move() def clicked8(self, event): # Event listener method for the button of the game at 2x1. # Parameters: # event Click event. if self.board[2][1] != ' ': return self.board[2][1] = 'X' self.set_dizzy(self.button8) self.computer_move() def clicked9(self, event): # Event listener method for the button of the game at 2x2. # # Parameters: # event Click event. if self.board[2][2] != ' ': return self.board[2][2] = 'X' self.set_dizzy(self.button9) self.computer_move() # Makes the next move on the board on behalf of the computer. def computer_move(self): # first move optimization - always start in the middle if possible if self.board[1][1] == ' ': self.board[1][1] = '0' self.set_mario(self.buttons_mapped[1][1]) self.test_state() return while self.has_empty_cell(): y = random.randint(0, self.cells - 1) x = random.randint(0, self.cells - 1) if self.board[y][x] == ' ': self.board[y][x] = '0' self.set_mario(self.buttons_mapped[y][x]) break self.test_state() def test_state(self): # Tests the board for a winning state. # If there is a winner then stops currently playing # background sound, creates winning label, plays result # sound and notifies/asks the user about continuation. if self.is_any_line_filled('X'): self.winner = self.dizzy # dizzy elif self.is_any_line_filled('0'): self.winner = self.mario # mario elif not self.has_empty_cell(): self.winner = self.blank # tie if self.winner: label = 'Tie.' self.stop_playing_background() if self.winner == self.mario: label = 'You lose!' self.play_sound_safe(self.lose_sound) elif self.winner == self.dizzy: label = 'You won!' self.play_sound_safe(self.won_sound) else: self.play_sound_safe(self.tie_sound) self.notify_and_ask_about_continuation(label) def notify_and_ask_about_continuation(self, label): # Shows modal window with the result of the game and asks the use whether they want to # continue the game. # If user answers "Y" or "y" restarts the game. # If user answers "N" or "n" closes the game window and frees the resources. # Parameters: # label Game result label. answer = None self.status_label.setText(label) while True: answer = str( requestString(label + "\r\n" + "Do you want to play again? (Y/N)")) if answer.lower() == "y": self.restart() break elif answer.lower() == "n": self.windowClosing(None) break def is_any_line_filled(self, character): # Checks the winning condition for the given character 'X' or '0'. # # Returns: # Whether the given character 'X' or '0' has a winning line filled. is_row = self.is_row_filled(character) is_col = self.is_col_filled(character) is_d1 = self.is_diag_filled1(character) is_d2 = self.is_diag_filled2(character) return is_row or is_col or is_d1 or is_d2 def has_empty_cell(self): #Checks if the game board contains an empty cell for the next move. # #Returns: # Whether there is an empty cell on the board. for row in range(len(self.board)): for col in range(len(self.board)): if self.board[row][col] == ' ': return True return False def is_row_filled(self, color): # Check row win condition. # # Parameters: # color (string) - color to check if the whole row of the same color # Returns: # True (boolean) - if the whole row of the same color # False (boolean) - if the row is not of the same color for row in range(len(self.board)): count = 0 for col in range(len(self.board)): if self.board[row][col] == color: count = count + 1 if count == self.cells: return True return False def is_col_filled(self, color): #Check column win condition. # # Parameters: # color (string) - color to check if the whole column of the same color # Returns: # True (boolean) - if the whole column of the same color # False (boolean) - if the column is not of the same color for col in range(len(self.board)): count = 0 for row in range(len(self.board)): if self.board[row][col] == color: count = count + 1 if count == self.cells: return True return False def is_diag_filled1(self, color): # Checks first diagonal win condition. # # Parameters: # color (string) - color to check if the whole diagonal of the same color # Returns: # True (boolean) - if the whole diagonal of the same color # False (boolean) - if the diagonal is not of the same color count = 0 for idx in range(len(self.board)): if self.board[idx][idx] == color: count = count + 1 return count == self.cells def is_diag_filled2(self, color): # Checks second diagonal win condition. # # Parameters: # color (string) - color to check if the whole diagonal of the same color # Returns: # True (boolean) - if the whole diagonal of the same color # False (boolean) - if the diagonal is not of the same color count = 0 for idx in range(len(self.board)): if self.board[idx][self.cells - 1 - idx] == color: count = count + 1 return count == self.cells def play_sound_safe(self, sound): # Method tries to play given sound catching possible exceptions. # For example, if the sound wasn't found in resource directory # # Parameters: # sound string with a file of a sound with leading slash '/'. # Returns: # Created Sound object fromo makeSound. snd = None try: snd = makeSound(self.resources_directory + sound) play(snd) except: showError("Error while playing sound " + str(sound) + ".") return snd def windowClosing(self, event): # Method is invoked when a user closes game window or finishes playing. # It is the implementation of WindowAdapter interface. # # Parameters: final event from Swing/AWT self.stop_playing_background() self.buttons = [] self.buttons_mapped = [] self.button1 = None self.button2 = None self.button3 = None self.button4 = None self.button5 = None self.button6 = None self.button7 = None self.button8 = None self.button9 = None self.status_label = None self.frame.getContentPane().removeAll() self.frame.dispose() self.frame = None def choosePlayer(self): while true: select = requestString( "You are against Mario. Choose Your Character: penguin chrome fox fish bird charizard sonic " ) selection = select.lower() if selection == "penguin": return rpenguin break if selection == "chrome": return rchrome break if selection == "fox": return rfox break if selection == "fish": return rfish break if selection == "bird": return rbird break if selection == "charizard": return rcharizard break if selection == "sonic": return rsonic break
def updateTeacherForm(data): global heading global tfTeacherName global tfTeacherPhone global taTeacherAddress global tfTeacherEmail global tfTeacherCourse global tfTeacherPayment global frame global btnEnter frame = JFrame(" Teacher ") frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) frame.setSize(500, 600) frame.setLocation(200, 200) frame.setLayout(None) frame.setVisible(True) panel = JPanel() panel.setSize(500, 600) panel.setLocation(0, 0) panel.setLayout(None) panel.setVisible(True) panel.setBackground(Color.LIGHT_GRAY) heading = JLabel(" TEACHER PROFILE") heading.setBounds(200, 30, 150, 40) lbTeacherName = JLabel("Teacher Name ") lbTeacherPhone = JLabel("Phone") lbTeacherEmail = JLabel("Email") lbTeacherAddress = JLabel("Address") lbTeacherCourse = JLabel("Teacher Course ") lbTeacherPayment = JLabel("Teacher Payment") teacherName = data[0].encode('ascii') teacherPhone = data[1].encode('ascii') teacherEmail = data[2].encode('ascii') teacherAddress = data[3].encode('ascii') teacherCourse = data[4].encode('ascii') teacherPayment = data[5] tfTeacherName = JTextField(teacherName) tfTeacherPhone = JTextField(teacherPhone) taTeacherAddress = JTextArea(teacherAddress) tfTeacherEmail = JTextField(teacherEmail) tfTeacherCourse = JTextField(teacherCourse) tfTeacherPayment = JTextField(str(teacherPayment)) tfTeacherCourse.setEditable(False) tfTeacherPayment.setEditable(False) tfTeacherName.setEditable(False) lbTeacherName.setBounds(70, 100, 130, 30) lbTeacherPhone.setBounds(70, 150, 130, 30) lbTeacherEmail.setBounds(70, 200, 130, 30) lbTeacherAddress.setBounds(70, 250, 130, 30) lbTeacherCourse.setBounds(70, 350, 130, 30) lbTeacherPayment.setBounds(70, 400, 130, 30) tfTeacherName.setBounds(220, 100, 130, 30) tfTeacherPhone.setBounds(220, 150, 130, 30) tfTeacherEmail.setBounds(220, 200, 130, 30) taTeacherAddress.setBounds(220, 250, 130, 80) tfTeacherCourse.setBounds(220, 350, 130, 30) tfTeacherPayment.setBounds(220, 400, 130, 30) btnEnter = JButton("Update", actionPerformed=clickUpdateTeacher) btnEnter.setBounds(350, 450, 100, 40) btnCancel = JButton("Cancel", actionPerformed=clickCancel) btnCancel.setBounds(100, 450, 100, 40) panel.add(heading) panel.add(lbTeacherName) panel.add(lbTeacherPhone) panel.add(lbTeacherEmail) panel.add(lbTeacherAddress) panel.add(lbTeacherCourse) panel.add(lbTeacherPayment) panel.add(tfTeacherName) panel.add(tfTeacherPhone) panel.add(tfTeacherEmail) panel.add(taTeacherAddress) panel.add(tfTeacherCourse) panel.add(tfTeacherPayment) panel.add(btnEnter) panel.add(btnCancel) frame.add(panel)
for i in range(0, rm.getCount()): roi = rm.getRoi(i) new_roi = RoiEnlarger.enlarge(roi, -pixels) # Key to use this instead of the IJ.run("Enlarge... much faster!! rm.setRoi(new_roi,i) gvars['eroded_pixels'] = pixels # Store globally the amount of pixels used to later save them in the ROI file name ########################################################### #################### Window #1 ########################### ########################################################### frame1 = JFrame("LabelToRoi: Single or Multiple") frame1.setLocation(100,100) frame1.setSize(450,200) frame1.setLayout(None) def clic_single(event): frame1.setVisible(False) frame2.setVisible(True) def clic_multiple(event): print("Click Multiple") frame1.setVisible(False) frame4.setVisible(True) # Single Image Button btn_single = JButton("Single Image", actionPerformed = clic_single) btn_single.setBounds(120,20,200,50) # Multiple Image Button
def __init__(self): frame = JFrame("S1riu5 Spy") frame.setSize(700, 690) frame.setLocationRelativeTo(None); frame.setLayout(BorderLayout()) tabPane = JTabbedPane(JTabbedPane.TOP) #第一个Tab用来做C段查询 eachIp = self.getIp(HOSTDOMAIN) iList = eachIp.split(".") theIP = iList[0] + "." + iList[1] + "." + iList[2] + ".1/24" panel1 = JPanel() label = JLabel("IP CIDR:") self.textfield1 = JTextField(theIP, 15) button = JButton("SCAN", actionPerformed = self.cNmapScan) self.textArea = JTextArea(40, 65) self.textArea.append("IP: " + eachIp) self.textArea.setLineWrap(True) #激活自动换行功能 self.textArea.setWrapStyleWord(True); # 激活断行不断字功能 panel1.add(label) panel1.add(self.textfield1) panel1.add(button) panel1.add(JScrollPane(self.textArea)) #设置自动滚动条 tabPane.addTab("C segment query ", panel1) #第二个Tab用来做子域名查询 theName = self.getDomain1(HOSTDOMAIN) self.textArea2 = JTextArea(40, 65) #self.textArea.append("IP: " + eachIp) self.textArea2.setLineWrap(True) #激活自动换行功能 self.textArea2.setWrapStyleWord(True) # 激活断行不断字功能 label2 = JLabel("Domain: ") self.textfield2 = JTextField(theName, 15) button2 = JButton("SCAN", actionPerformed = self.subDomain) self.panel2 = JPanel() self.panel2.add(label2) self.panel2.add(self.textfield2) self.panel2.add(button2) #self.panel2.add(scrollPane) self.panel2.add(JScrollPane(self.textArea2)) tabPane.addTab("subDomains", self.panel2) #第三个Tab用来做敏感文件扫描 self.tableData0 = [["1", "2"]] colNames2 = ('url','http code') dataModel3 = DefaultTableModel(self.tableData0, colNames2) self.table3 = JTable(dataModel3) ## label3 = JLabel("URL: ") self.textfield3 = JTextField(HOSTDOMAIN, 15) self.textArea3 = JTextArea(40, 65) #self.textArea.append("IP: " + eachIp) self.textArea3.setLineWrap(True) #激活自动换行功能 self.textArea3.setWrapStyleWord(True) # 激活断行不断字功能 a = 0 b = 0 self.label4 = JLabel(str(a) + "/" + str(b)) # self.chkbox1 = JCheckBox('ASP') self.chkbox2 = JCheckBox('ASPX') self.chkbox3 = JCheckBox('JSP') self.chkbox4 = JCheckBox('PHP') self.chkbox5 = JCheckBox('MDB') self.chkbox6 = JCheckBox('DIR') button3 = JButton("SCAN", actionPerformed = self.senFileScan) panel3 = JPanel() panel3.add(label3) panel3.add(self.textfield3) panel3.add(self.chkbox1) panel3.add(self.chkbox2) panel3.add(self.chkbox3) panel3.add(self.chkbox4) panel3.add(self.chkbox5) panel3.add(self.chkbox6) panel3.add(button3) panel3.add(self.label4) panel3.add(JScrollPane(self.textArea3)) # tabPane.addTab("Sebsitive File", panel3) # frame.add(tabPane) frame.setVisible(True)
def __init__(self): frame = JFrame("S1riu5 Spy") frame.setSize(700, 690) frame.setLocationRelativeTo(None) frame.setLayout(BorderLayout()) tabPane = JTabbedPane(JTabbedPane.TOP) #第一个Tab用来做C段查询 eachIp = self.getIp(HOSTDOMAIN) iList = eachIp.split(".") theIP = iList[0] + "." + iList[1] + "." + iList[2] + ".1/24" panel1 = JPanel() label = JLabel("IP CIDR:") self.textfield1 = JTextField(theIP, 15) button = JButton("SCAN", actionPerformed=self.cNmapScan) self.textArea = JTextArea(40, 65) self.textArea.append("IP: " + eachIp) self.textArea.setLineWrap(True) #激活自动换行功能 self.textArea.setWrapStyleWord(True) # 激活断行不断字功能 panel1.add(label) panel1.add(self.textfield1) panel1.add(button) panel1.add(JScrollPane(self.textArea)) #设置自动滚动条 tabPane.addTab("C segment query ", panel1) #第二个Tab用来做子域名查询 theName = self.getDomain1(HOSTDOMAIN) self.textArea2 = JTextArea(40, 65) #self.textArea.append("IP: " + eachIp) self.textArea2.setLineWrap(True) #激活自动换行功能 self.textArea2.setWrapStyleWord(True) # 激活断行不断字功能 label2 = JLabel("Domain: ") self.textfield2 = JTextField(theName, 15) button2 = JButton("SCAN", actionPerformed=self.subDomain) self.panel2 = JPanel() self.panel2.add(label2) self.panel2.add(self.textfield2) self.panel2.add(button2) #self.panel2.add(scrollPane) self.panel2.add(JScrollPane(self.textArea2)) tabPane.addTab("subDomains", self.panel2) #第三个Tab用来做敏感文件扫描 self.tableData0 = [["1", "2"]] colNames2 = ('url', 'http code') dataModel3 = DefaultTableModel(self.tableData0, colNames2) self.table3 = JTable(dataModel3) ## label3 = JLabel("URL: ") self.textfield3 = JTextField(HOSTDOMAIN, 15) self.textArea3 = JTextArea(40, 65) #self.textArea.append("IP: " + eachIp) self.textArea3.setLineWrap(True) #激活自动换行功能 self.textArea3.setWrapStyleWord(True) # 激活断行不断字功能 a = 0 b = 0 self.label4 = JLabel(str(a) + "/" + str(b)) # self.chkbox1 = JCheckBox('ASP') self.chkbox2 = JCheckBox('ASPX') self.chkbox3 = JCheckBox('JSP') self.chkbox4 = JCheckBox('PHP') self.chkbox5 = JCheckBox('MDB') self.chkbox6 = JCheckBox('DIR') button3 = JButton("SCAN", actionPerformed=self.senFileScan) panel3 = JPanel() panel3.add(label3) panel3.add(self.textfield3) panel3.add(self.chkbox1) panel3.add(self.chkbox2) panel3.add(self.chkbox3) panel3.add(self.chkbox4) panel3.add(self.chkbox5) panel3.add(self.chkbox6) panel3.add(button3) panel3.add(self.label4) panel3.add(JScrollPane(self.textArea3)) # tabPane.addTab("Sebsitive File", panel3) # frame.add(tabPane) frame.setVisible(True)
def instReg(): global frame global tfName global tfPhone global taAddress global tfAdminLoginId global tfAdminPassword frame = JFrame("Registration Form ") frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) frame.setSize(500,550) frame.setLocation(200,200) frame.setLayout(None) frame.setVisible(True) panel = JPanel() panel.setSize(500,550) panel.setLocation(0,0) panel.setLayout(None) panel.setBackground(Color.LIGHT_GRAY) heading = JLabel("Institute Registration Form ") heading.setBounds(200,30,150,30) lbName = JLabel("Name") lbPhone =JLabel("Phone no ") lbAddress = JLabel("Address") lbAdminLoginId = JLabel("Admin login ") lbAdminPassword =JLabel("Admin Password") font = Font("Courier",Font.PLAIN,16) tfName = JTextField() tfPhone = JTextField() taAddress =JTextArea() tfAdminLoginId = JTextField() tfAdminPassword = JTextField() lbName.setBounds(70,100,150,40) lbPhone.setBounds(70,150,150,40) lbAddress.setBounds(70,200,150,40) lbAdminLoginId.setBounds(70,310,150,40) lbAdminPassword.setBounds(70,360,150,40) tfName = JTextField() tfPhone = JTextField() taAddress = JTextArea() tfAdminLoginId = JTextField() tfAdminPassword = JTextField() tfName.setBounds(250,100,200,40) tfPhone.setBounds(250,150,200,40) taAddress.setBounds(250,200,200,100) tfAdminLoginId.setBounds(250,310,200,40) tfAdminPassword.setBounds(250,360,200,40) tfName.setFont(font) tfPhone.setFont(font) taAddress.setFont(font) tfAdminLoginId.setFont(font) tfAdminPassword.setFont(font) sp = JScrollPane(taAddress) c = frame.getContentPane() btnSave = JButton("Save",actionPerformed=clickAdminReg) btnSave.setBounds(350,420,80,30) #panel.add(lbName) #panel.add(lbPhone) #panel.add(lbAddress) #panel.add(lbAdminLoginId) #panel.add(lbAdminPassword) #panel.add(tfName) #panel.add(tfPhone) #panel.add(c) #panel.add(tfAdminLoginId) #panel.add(tfAdminPassword) #panel.add(btnSave) #panel.add(btnLogin) c.add(lbName) c.add(lbPhone) c.add(lbAddress) c.add(lbAdminLoginId) c.add(lbAdminPassword) c.add(tfName) c.add(tfPhone) c.add(taAddress) c.add(tfAdminLoginId) c.add(tfAdminPassword) c.add(btnSave) frame.add(c)
def __init__(self): self.panel = JPanel() self.panel.setLayout(BorderLayout()) frame = JFrame("GUI Development ") frame.setSize(800, 600) frame.setLayout(BorderLayout()) splitPane = JSplitPane(JSplitPane.VERTICAL_SPLIT); self.textfield1 = JTextField('Type something here') self.textfield1.setColumns(40); #self.textfield1.setRows(5); #self.textfield2 = JTextField('Dont write anythong',30) label1 = JLabel("Command:") panel1 = JPanel() ''' ''' jMenuBar1 = JMenuBar() jMenu1 = JMenu() jMenu2 = JMenu() jMenuItem1 = JMenuItem('Open', actionPerformed=self.onClick) jMenuItem2 = JMenuItem() jMenu1.setText('File') jMenu2.setText('Simulation') #jMenuItem1.setText('Open') jMenuItem2.setText('Exit') jMenu1.add(jMenuItem1) jMenu1.add(jMenuItem2) jMenuBar1.add(jMenu1) jMenuItem21 = JMenuItem('Simulation Options',actionPerformed=self.writeText) jMenuItem22 = JMenuItem('Simulate',actionPerformed=self.writeText) jMenuItem23 = JMenuItem('Generate FMU',actionPerformed=self.writeText) # jMenuItem21.setText('Run Project') # jMenuItem22.setText('Generate FMU') jMenu2.add(jMenuItem21) jMenu2.add(jMenuItem22) jMenu2.add(jMenuItem23) jMenuBar1.add(jMenu2) frame.setJMenuBar(jMenuBar1) ''' ''' panel1.add(label1,BorderLayout.WEST) panel1.add(self.textfield1, BorderLayout.CENTER) copyButton = JButton('send',actionPerformed=self.copyText) panel1.add(copyButton, BorderLayout.EAST) #panel1.add(self.textfield2, BorderLayout.SOUTH) splitPane.setLeftComponent(panel1); ''' image adding in the frame ''' #imPanel.add(imPanel,BorderLayout.WEST) #imPanel.setBackground(Color(66, 66, 66)) imPanel1 = JPanel() rot = ImageIcon("ballon.jpg") rotLabel = JLabel(rot) rotLabel.setBounds(0,0, rot.getIconWidth(), rot.getIconHeight()) imPanel1.add(rotLabel, BorderLayout.SOUTH) frame.add(imPanel1, BorderLayout.SOUTH) ''' panel for text area adding in split pan ''' tabPane = JTabbedPane(JTabbedPane.TOP) label = JLabel("<html><br>This is a tab1</html>") panel1 = JPanel() panel1.setBackground(Color.lightGray) panel23 = JPanel() panel23.setBackground(Color.black) panel1.add(panel23,BorderLayout.SOUTH) panel1.add(label,BorderLayout.NORTH) ''' adding button in the panel1 ''' writeButton = JButton('write') panel1.add(writeButton, BorderLayout.WEST) tabPane.addTab("tab1", panel1) #frame.add(panel1,BorderLayout.EAST) #panel1.setBackground(Color(66, 66, 66)) # rot1 = ImageIcon("ballon.jpg",BorderLayout.SOUTH) # rotLabel1 = JLabel(rot1) # rotLabel1.setBounds(0,0, rot.getIconWidth(), rot.getIconHeight()) # panel1.add(rotLabel1) label2 = JLabel("This is a tab2") panel2 = JPanel() panel2.setBackground(Color.lightGray) panel2.add(label2) tabPane.addTab("tab2", panel2) # imPanel2 =JPanel() self.textarea = JTextArea('Write something from commandLine') self.textarea.setColumns(40); self.textarea.setRows(40); panel2.add(self.textarea, BorderLayout.NORTH) splitPane.setRightComponent(tabPane); splitPane.setDividerLocation(60); frame.add(splitPane) frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE) frame.setVisible(True)