本文整理汇总了Python中javax.swing.JFrame.setIconImage方法的典型用法代码示例。如果您正苦于以下问题:Python JFrame.setIconImage方法的具体用法?Python JFrame.setIconImage怎么用?Python JFrame.setIconImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JFrame
的用法示例。
在下文中一共展示了JFrame.setIconImage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from javax.swing import JFrame [as 别名]
# 或者: from javax.swing.JFrame import setIconImage [as 别名]
def run(scene, w=512, h=512, aa=1, threads=1):
"""Create GUI and perform ray-tracing."""
# Make Swing not look like garbage (so much)
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
# Setup frame
frame = JFrame("RayTracer", defaultCloseOperation=JFrame.EXIT_ON_CLOSE, size=(w, h))
frame.setIconImage(ImageIcon("resources/icon.png").getImage())
canvas = RayTracePanel(w, h, aa, threads)
frame.getContentPane().add(JScrollPane(canvas))
# Save FileChooser
fcS = JFileChooser()
fcS.addChoosableFileFilter(FileNameExtensionFilter("Windows Bitmap (*.bmp)", ["bmp"]))
fcS.addChoosableFileFilter(FileNameExtensionFilter("JPEG / JFIF (*.jpg)", ["jpg"]))
fcS.addChoosableFileFilter(FileNameExtensionFilter("Portable Network Graphics (*.png)", ["png"]))
def saveFile(event):
"""Performed when the save button is pressed"""
result = fcS.showSaveDialog(frame)
if result == JFileChooser.APPROVE_OPTION:
file = fcS.getSelectedFile()
fname = file.getPath()
ext = fcS.getFileFilter().getExtensions()[0]
if not fname.endswith("." + ext):
file = File(fname + "." + ext)
canvas.saveToFile(file, ext)
# Open FileChooser
fcO = JFileChooser()
fcO.addChoosableFileFilter(FileNameExtensionFilter("RayTrace Scene File (*.rts)", ["rts"]))
def openFile(event):
"""Performed when the open button is pressed"""
result = fcO.showOpenDialog(frame)
if result == JFileChooser.APPROVE_OPTION:
fname = fcO.getSelectedFile().getPath()
if fname.endswith(".rts"):
f = open(fname, "rb")
newScene = SceneFactory().buildScene(f)
f.close()
Painter(canvas, newScene, openButton, saveButton, stopButton).start()
def exit(event):
"""Performed when the exit button is pressed"""
import sys
sys.exit(0)
def stop(event):
"""Peformed when the stop button is pressed"""
canvas.stopRendering()
# Setup Menu
menuBar = JMenuBar()
menu = JMenu("File")
menuBar.add(menu)
openButton = JMenuItem("Open...", actionPerformed=openFile)
openButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK))
menu.add(openButton)
saveButton = JMenuItem("Save as...", actionPerformed=saveFile)
saveButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK))
menu.add(saveButton)
menu.addSeparator()
stopButton = JMenuItem("Stop Render", actionPerformed=stop)
stopButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0))
stopButton.setEnabled(False)
menu.add(stopButton)
menu.addSeparator()
closeButton = JMenuItem("Close", actionPerformed=exit)
closeButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK))
menu.add(closeButton)
frame.setJMenuBar(menuBar)
# Finish initializing GUI
self.pack()
示例2: run
# 需要导入模块: from javax.swing import JFrame [as 别名]
# 或者: from javax.swing.JFrame import setIconImage [as 别名]
def run(scene, w=512, h=512, aa=1, threads=1):
'''Create GUI and perform ray-tracing.'''
#Make Swing not look like garbage (so much)
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
#Setup frame
frame = JFrame(
"RayTracer",
defaultCloseOperation=JFrame.EXIT_ON_CLOSE,
size=(w, h)
)
frame.setIconImage(ImageIcon('resources/icon.png').getImage())
canvas = RayTracePanel(w, h, aa, threads)
frame.getContentPane().add(JScrollPane(canvas))
#Save FileChooser
fcS = JFileChooser()
fcS.addChoosableFileFilter(FileNameExtensionFilter('Windows Bitmap (*.bmp)', ['bmp']))
fcS.addChoosableFileFilter(FileNameExtensionFilter('JPEG / JFIF (*.jpg)', ['jpg']))
fcS.addChoosableFileFilter(FileNameExtensionFilter('Portable Network Graphics (*.png)', ['png']))
def saveFile(event):
'''Performed when the save button is pressed'''
result = fcS.showSaveDialog(frame)
if result == JFileChooser.APPROVE_OPTION:
file = fcS.getSelectedFile()
fname = file.getPath()
ext = fcS.getFileFilter().getExtensions()[0]
if not fname.endswith('.' + ext):
file = File(fname + '.' + ext)
canvas.saveToFile(file, ext)
#Open FileChooser
fcO = JFileChooser()
fcO.addChoosableFileFilter(FileNameExtensionFilter('RayTrace Scene File (*.rts)', ['rts']))
def openFile(event):
'''Performed when the open button is pressed'''
result = fcO.showOpenDialog(frame)
if result == JFileChooser.APPROVE_OPTION:
fname = fcO.getSelectedFile().getPath()
if fname.endswith('.rts'):
f = open(fname, 'rb')
newScene = SceneFactory().buildScene(f)
f.close()
Painter(canvas, newScene, openButton, saveButton).start()
def exit(event):
'''Performed when the exit button is pressed'''
import sys
sys.exit(0)
#Setup Menu
menuBar = JMenuBar()
menu = JMenu("File")
menuBar.add(menu)
openButton = JMenuItem("Open...", actionPerformed=openFile)
openButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK))
menu.add(openButton)
saveButton = JMenuItem("Save as...", actionPerformed=saveFile)
saveButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK))
menu.add(saveButton)
menu.addSeparator()
closeButton = JMenuItem('Close', actionPerformed=exit)
closeButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK))
menu.add(closeButton)
frame.setJMenuBar(menuBar)
#Finish initializing GUI
frame.pack()
#frame.setLocationRelativeTo(None)
frame.setVisible(True)
#Perform ray-tracing
if scene is not None:
Thread(Painter(canvas, scene, openButton, saveButton)).start()