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


Python JFrame.setMinimumSize方法代码示例

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


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

示例1: Gui

# 需要导入模块: from javax.swing import JFrame [as 别名]
# 或者: from javax.swing.JFrame import setMinimumSize [as 别名]
class Gui(MouseAdapter):
    IMG_MIN_SIZE = 200
    IMG_MAX_SIZE = 500

    def __init__(self):
        self.pos1 = None
        self.puzzle = None

    def mouseEntered(self, event):
        self.in_canvas = True

    def mouseExited(self, event):
        self.in_canvas = False

    def mouseReleased(self, event):
        if not self.in_canvas or self.puzzle == None:
            return

        width = self.images_dict[0].getWidth()
        height = self.images_dict[0].getHeight()

        def valid_pos(pos):
            return pos >= 0 and pos < self.puzzle.level()

        x = (event.getX() - self.canvas.initial_x) / width
        y = (event.getY() - self.canvas.initial_y) / height

        if not valid_pos(x) or not valid_pos(y):
            return

        pos = Point(x, y)
        if self.pos1 != None: #then is second click
            if self.pos1.equals(pos):
                self.pos1 = None
            else:
                self.play_event(self.pos1.y, self.pos1.x, pos.y, pos.x)
                self.pos1 = None
        else:
            self.pos1 = pos
        self.canvas.set_selected(self.pos1)
        self.canvas.repaint()

    def draw(self):

        try:
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        except:
            pass

        self.images_dict = dict()
        self.canvas = Canvas(self.images_dict, None)
        self.canvas.addMouseListener(self)

        self.frame = JFrame("SimplePyzzle", visible = 1)
        self.frame.setMinimumSize(Dimension(300, 300))
        self.frame.setLocationRelativeTo(None)
        self.generate_button = JButton("Generate Puzzle")
        self.bottom_panel = JPanel()

        self.combo_box_list = [9, 16, 25, 36, 49]
        self.combo_box = JComboBox(self.combo_box_list)

        self.frame.contentPane.add(self.canvas, BorderLayout.CENTER)
        self.frame.contentPane.add(self.bottom_panel, BorderLayout.SOUTH)
        self.bottom_panel.add(self.generate_button, BorderLayout.EAST)
        self.bottom_panel.add(self.combo_box, BorderLayout.WEST)

        self.generate_button.actionPerformed = self.generate_board

        self.frame.setSize(500, 500)
        self.frame.defaultCloseOperation = JFrame.EXIT_ON_CLOSE;
        self.frame.pack()

    def generate_board(self, event):

        chooser = JFileChooser()
        status = chooser.showOpenDialog(self.frame)
        if status != JFileChooser.APPROVE_OPTION:
            return

        imageFile = chooser.getSelectedFile()

        self.puzzle = SimplePyzzle(float(int(self.combo_box.getSelectedItem())))
        self.draw_board()
        self.load_images(imageFile, self.puzzle.level())
        self.canvas.set_puzzle(self.puzzle)
        width = self.images_dict[0].getWidth()
        height = self.images_dict[0].getHeight()
        size = Dimension(width * self.puzzle.level(), height * self.puzzle.level())
        self.frame.setPreferredSize(size)
        self.frame.setSize(size)

    def show_error(self, error):
        JOptionPane.showMessageDialog(self.frame, \
                                    error, \
                                    "Error!", \
                                    JOptionPane.ERROR_MESSAGE)

    def load_images(self, file, length):

#.........这里部分代码省略.........
开发者ID:pythonoob,项目名称:SimplePyzzle,代码行数:103,代码来源:Gui.py


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