当前位置: 首页>>代码示例>>Python>>正文


Python JTextArea.getFont方法代码示例

本文整理汇总了Python中javax.swing.JTextArea.getFont方法的典型用法代码示例。如果您正苦于以下问题:Python JTextArea.getFont方法的具体用法?Python JTextArea.getFont怎么用?Python JTextArea.getFont使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JTextArea的用法示例。


在下文中一共展示了JTextArea.getFont方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: HandRecoWriter

# 需要导入模块: from javax.swing import JTextArea [as 别名]
# 或者: from javax.swing.JTextArea import getFont [as 别名]

#.........这里部分代码省略.........
        word_classifier_file.close()
        #Set up window
        self.setTitle("HandReco Writer")
        self.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
        self.setLocationRelativeTo(None)
        self.setLayout(BorderLayout())
        #Set up menu
        menu_bar = JMenuBar()
        info_menu = JMenu("Info")
        def instructions(event):
            instr = '''
            The program can just recognise capital English characters.
            See Info -> Available Words... for available word corrections.
            
            Good Luck with the writing!'''
            JOptionPane.showMessageDialog(self, instr, 
                          "Instructions", 
                          JOptionPane.INFORMATION_MESSAGE)
        instructions_menu_item = JMenuItem("Instructions...",actionPerformed=instructions)
        info_menu.add(instructions_menu_item)
        def word_corrections(event):
            words_string = ""
            for word in self.word_classifier.words:
                words_string = words_string + word.upper() + "\n"
            text = "The words that can be corrected are:\n\n" +words_string
            dialog = JOptionPane(text, 
                                 JOptionPane.INFORMATION_MESSAGE)
            dialog_wrapper = JDialog(self,"Available Words",False)
            dialog_wrapper.setContentPane(dialog)
            dialog_wrapper.pack()
            dialog_wrapper.setVisible(True)
        word_corrections_menu_item = JMenuItem("Available Words...",actionPerformed=word_corrections)
        info_menu.add(word_corrections_menu_item)
        menu_bar.add(info_menu)
        self.setJMenuBar(menu_bar)
        #Input panel
        input_panel = JPanel()
        input_panel.setLayout(BoxLayout(input_panel, BoxLayout.X_AXIS))
        input_panel.setBorder(BorderFactory.createTitledBorder("Input"))
        self.paint_area = PaintArea(100,100)
        input_panel.add(self.paint_area)
        input_options_panel = JPanel()
        input_options_panel.setLayout(BoxLayout(input_options_panel, BoxLayout.Y_AXIS))
        #Write Char
        write_char_panel = JPanel(BorderLayout())
        def write_char(event):
            char = self.character_classifier.classify_image(self.paint_area.image())
            self.text_area.setText(self.text_area.getText() + char)
            self.paint_area.clear()
        write_char_panel.add(JButton("Write Char", actionPerformed=write_char), BorderLayout.NORTH)
        input_options_panel.add(write_char_panel)
        #Space and Correct
        space_and_correct_panel = JPanel(BorderLayout())
        def space_and_correct(event):
            text = self.text_area.getText()
            words = text.split(" ")
            string = words[-1]
            try:
                word = self.word_classifier.classify(string.lower())
                words[-1] = word.upper()
            except:
                JOptionPane.showMessageDialog(self, "Have you entered a character which is not in the alphabet?", 
                              "Could not Correct", 
                              JOptionPane.ERROR_MESSAGE)
                self.text_area.setText(text + " ")
                return
            newText = ""
            for w in words:
                newText = newText + w + " "
            self.text_area.setText(newText)
        space_and_correct_panel.add(JButton("Space and Correct", actionPerformed=space_and_correct), BorderLayout.NORTH)
        input_options_panel.add(space_and_correct_panel)
        #Space
        space_panel = JPanel(BorderLayout())
        def space(event):
            self.text_area.setText(self.text_area.getText() + " ")
        space_panel.add(JButton("Space", actionPerformed=space), BorderLayout.NORTH)
        input_options_panel.add(space_panel)
        #Clear Input Area
        clear_input_area_panel = JPanel(BorderLayout())
        def clear(event):
            self.paint_area.clear()
        clear_input_area_panel.add(JButton("Clear Input Area", actionPerformed=clear), BorderLayout.NORTH)
        input_options_panel.add(clear_input_area_panel)
        input_panel.add(input_options_panel)
        self.add(input_panel, BorderLayout.NORTH)
        text_area_panel = JPanel()
        text_area_panel.setLayout(BorderLayout())
        text_area_panel.setBorder(BorderFactory.createTitledBorder("Text"))
        self.text_area = JTextArea()
        self.text_area.setLineWrap(True)
        #Increase font size
        font = self.text_area.getFont() 
        self.text_area.setFont(Font(font.getName(), Font.BOLD, 24))
        
        text_area_panel.add(JScrollPane(self.text_area), BorderLayout.CENTER)
        self.add(text_area_panel, BorderLayout.CENTER)
        self.pack()
        self.setSize(Dimension(300,300))
        self.setVisible(True)
开发者ID:Yinhai,项目名称:HandReco,代码行数:104,代码来源:hand_reco_writer.py


注:本文中的javax.swing.JTextArea.getFont方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。