本文整理汇总了Python中javax.swing.JFrame.setJMenuBar方法的典型用法代码示例。如果您正苦于以下问题:Python JFrame.setJMenuBar方法的具体用法?Python JFrame.setJMenuBar怎么用?Python JFrame.setJMenuBar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JFrame
的用法示例。
在下文中一共展示了JFrame.setJMenuBar方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: makeEditorFrame
# 需要导入模块: from javax.swing import JFrame [as 别名]
# 或者: from javax.swing.JFrame import setJMenuBar [as 别名]
def makeEditorFrame(ldPath, compiler):
mb = JMenuBar()
file = JMenu("File")
edit = JMenu("Edit")
run = JMenu("Run")
newMenu = menu_with_accelerator("New",(KeyEvent.VK_N,ActionEvent.META_MASK))
file.add(newMenu)
open = menu_with_accelerator("Open",(KeyEvent.VK_O,ActionEvent.META_MASK))
file.add(open)
save = menu_with_accelerator("Save",(KeyEvent.VK_S,ActionEvent.META_MASK))
file.add(save)
file.add(JSeparator());
resetPipe = menu_with_accelerator("Reset Pipeline",(KeyEvent.VK_N,ActionEvent.META_MASK | ActionEvent.SHIFT_MASK))
file.add(resetPipe)
openPipe = menu_with_accelerator("Open Pipeline",(KeyEvent.VK_O,ActionEvent.META_MASK | ActionEvent.SHIFT_MASK))
file.add(openPipe)
compile = menu_with_accelerator("Compile",(KeyEvent.VK_ENTER, ActionEvent.META_MASK))
run.add(compile)
mb.add(file)
mb.add(edit)
mb.add(run)
f = JFrame("SFGP Shader Editor")
f.setJMenuBar(mb)
c = f.getContentPane()
c.setLayout(BorderLayout())
editor = GLSLEditorPane("",ldPath,compiler)
c.add(editor, BorderLayout.CENTER)
c.doLayout()
f.setSize(1000, 700);
f.setVisible(True);
f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
class EditorActionListener(ActionListener):
def makeRelay(srcObj):
return (lambda e: editor.actionPerformed(ActionEvent(srcObj, e.getID(), e.getActionCommand())))
editorActions = {
save : (lambda e: editor.saveCurrent()),
compile : (lambda e: editor.compileCurrent()),
open : makeRelay(editor.openShader),
newMenu : makeRelay(editor.newShader),
openPipe : makeRelay(editor.openPipeline),
resetPipe : makeRelay(editor.resetPipeline)
}
def actionPerformed(self, e):
editorActions = EditorActionListener.editorActions
evtSrc = e.getSource()
if evtSrc in editorActions:
editorActions[evtSrc](e)
else:
raise IllegalStateException("Imaginary menu item registered an ActionEvent: " + evtSrc)
menuListener = EditorActionListener()
compile.addActionListener(menuListener);
newMenu.addActionListener(menuListener);
open.addActionListener(menuListener);
save.addActionListener(menuListener);
resetPipe.addActionListener(menuListener);
openPipe.addActionListener(menuListener);
示例2: run
# 需要导入模块: from javax.swing import JFrame [as 别名]
# 或者: from javax.swing.JFrame import setJMenuBar [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()
示例3: PythonWindow
# 需要导入模块: from javax.swing import JFrame [as 别名]
# 或者: from javax.swing.JFrame import setJMenuBar [as 别名]
#.........这里部分代码省略.........
editmenu.add(new_item("Paste", "paste", KeyEvent.VK_V))
editmenu.addSeparator()
item = new_item("Run Script", "runscript", KeyEvent.VK_E)
editmenu.add(item)
item = new_item("Run Selection", "runselection", KeyEvent.VK_E,
mod=shortcut | ActionEvent.SHIFT_MASK)
editmenu.add(item)
editmenu.addSeparator()
item = new_item("Indent Selection", "indentselection",
KeyEvent.VK_CLOSE_BRACKET)
editmenu.add(item)
item = new_item("Dedent Selection", "dedentselection",
KeyEvent.VK_OPEN_BRACKET)
editmenu.add(item)
shellmenu = JMenu("Interactive")
menubar.add(shellmenu)
item = new_item("Previous Input", "up", KeyEvent.VK_UP,
mod=ActionEvent.ALT_MASK)
shellmenu.add(item)
item = new_item("Next Input", "down", KeyEvent.VK_DOWN,
mod=ActionEvent.ALT_MASK)
shellmenu.add(item)
self.frame.setJMenuBar(menubar)
def toggle_visibility(self):
self.frame.visible = not self.frame.visible
def add_component(self, c):
self.remove_component()
self.frame.add(c, BorderLayout.PAGE_START)
self.component = c
def remove_component(self):
if self.component is not None:
self.frame.remove(self.component)
self.component = None
def add(self, text, type="input"):
self.outputpane.addtext(text, type)
self.frame.validate()
def error(self, text):
self.outputpane.addtext(text, "error", ensure_newline=True)
def write(self, text):
self.add(text, "output")
# Code execution methods
def runcode(self, source, interactive=True):
if not source.strip():
return True
processed_source = source.replace("$", "geo.")
code = self.interface.compileinteractive(processed_source)
if code in ("continue", "error"):
code = self.interface.compilemodule(processed_source)
if code == "error":
return
if code == "error":
return False
source = source.strip()
示例4: __init__
# 需要导入模块: from javax.swing import JFrame [as 别名]
# 或者: from javax.swing.JFrame import setJMenuBar [as 别名]
class Window:
def __init__(self, text):
self.frame = JFrame()
self.frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE)
self.frame.getContentPane().setLayout(GridLayout(1, 1))
self.settings = Settings()
self.text = text
self + text
m = JMenuBar()
self.menubar = m
self.filemenu = self.menu()
m.add(self.filemenu)
self.frame.setJMenuBar(self.menubar)
self.frame.setSize(1000, 600)
self.frame.setVisible(1)
def menu(self):
f = JMenu("File")
o = JMenuItem("Copy")
o.addActionListener(ActionEventListener(self.opencopy))
self.open = o
f.add(o)
o = JMenuItem("New")
o.addActionListener(ActionEventListener(self.new))
self.open = o
f.add(o)
o = JMenuItem("Open")
o.addActionListener(ActionEventListener(self.opendialog))
self.open = o
f.add(o)
o = JMenuItem("Save")
o.addActionListener(ActionEventListener(self.save))
self.open = o
f.add(o)
o = JMenuItem("Save As")
o.addActionListener(ActionEventListener(self.saveas))
self.open = o
f.add(o)
return f
def __add__(self, c):
self.frame.getContentPane().add(c)
return self
def opencopy(self, e):
c = None
if "lastcopy" in self.settings.keys():
c = JFileChooser(self.settings["lastcopy"])
else:
c = JFileChooser()
r = c.showOpenDialog(self.frame)
if r == JFileChooser.APPROVE_OPTION:
f = c.getSelectedFile()
self.f = f
s = f.getAbsolutePath()
self.settings["lastcopy"] = f.getParent()
self.settings.save()
# i = FileInputStream(s)
self.text.setcopy(s)
def opendialog(self, e):
c = None
if "lastdir" in self.settings.keys():
c = JFileChooser(self.settings["lastdir"])
else:
c = JFileChooser()
r = c.showOpenDialog(self.frame)
if r == JFileChooser.APPROVE_OPTION:
f = c.getSelectedFile()
self.f = f
s = f.getAbsolutePath()
self.settings["lastdir"] = f.getParent()
self.settings.save()
i = FileInputStream(s)
self.text.setinput(i)
self.frame.pack()
self.frame.setSize(800, 500)
def new(self, e):
self.text.createnew()
self.frame.pack()
self.frame.setSize(800, 500)
def save(self, e):
o = FileOutputStream(self.f)
self.text.setoutput(o)
#.........这里部分代码省略.........
示例5: __init__
# 需要导入模块: from javax.swing import JFrame [as 别名]
# 或者: from javax.swing.JFrame import setJMenuBar [as 别名]
#.........这里部分代码省略.........
def getScreenSize(self):
return Toolkit.getDefaultToolkit().getScreenSize()
def setFrameLocation(self, side):
screenSize = self.getScreenSize()
if side == 'Right':
self._frame.setSize( int(screenSize.width * 0.31), int(screenSize.height * 0.95) )
self._frame.setLocation( int(screenSize.width * 0.69), 0 )
def playNowApp_startThread(self, action):
self.setFrameLocation("Right")
Thread(name="AppLaunch", target=self.launchPlayNowApp, args=(action,) ).start()
def setMenuBar(self):
menuBar = JMenuBar()
menuApp = JMenu("Apps")
menuApp.setMnemonic('A')
menuSettings = JMenu("Settings")
menuSettings.setMnemonic('S')
#set submenus
menuPlayNow = JMenu("PlayNow" )
menuPlayNowOpen = JMenuItem("Open", actionPerformed = (lambda x, param="open": self.playNowApp_startThread(param)) )
menuPlayNow.add(menuPlayNowOpen)
menuPlayNowLogin = JMenuItem("Login", actionPerformed = lambda x, action="playNowLogin": self.playNowApp_startThread(action) )
menuPlayNow.add(menuPlayNowLogin)
menuPlayNowClose = JMenuItem("Close", actionPerformed = lambda x, action="playNowClose": self.playNowApp_startThread(action) )
menuPlayNow.add(menuPlayNowClose)
menuPokerTable = JMenu("PokerTable")
menuPokerTableJoin = JMenuItem("Find Practice Table", actionPerformed = lambda x, action="practiceTable": self.playNowApp_startThread(action) )
menuPokerTable.add(menuPokerTableJoin)
menuPokerTableJoin = JMenuItem("Join Table", actionPerformed = lambda x, action="joinTable": self.playNowApp_startThread(action) )
menuPokerTable.add(menuPokerTableJoin)
menuPokerTableAddChips = JMenuItem("Add Chips", actionPerformed = lambda x, action="addChips": self.playNowApp_startThread(action) )
menuPokerTable.add(menuPokerTableAddChips)
menuPokerTableSitOut = JMenuItem("Sit Out", actionPerformed = lambda x, action="sitOut": self.playNowApp_startThread(action) )
menuPokerTable.add(menuPokerTableSitOut)
menuPokerTableLeaveTable = JMenuItem("Leave Table", actionPerformed = lambda x, action="leaveTable": self.playNowApp_startThread(action) )
menuPokerTable.add(menuPokerTableLeaveTable)
menuPokerAppExit = JMenuItem("Exit")
menuApp.add(menuPlayNow)
menuApp.add(menuPokerTable)
menuApp.addSeparator()
menuApp.add(menuPokerAppExit)
menuBar.add(menuApp)
menuBar.add(menuSettings)
self._frame.setJMenuBar(menuBar)
def startGui(self):
# self.gridPanel = JPanel(GridLayout(self.numRows, self.numCols))
# self.cellButtons = self._doForAllCells(self._createCellButton)
# self.grid = self._doForAllCells(lambda r,c: False)
# frame.add(self.gridPanel)
# buttonPanel = JPanel(FlowLayout())
# stepButton = JButton("Step", actionPerformed=self._step)
# runButton = JToggleButton("Run", actionPerformed=self._run)
# buttonPanel.add(stepButton)
# buttonPanel.add(runButton)
# frame.add(buttonPanel, SOUTH)
# frame.pack()
# frame.locationRelativeTo = None
self.setMenuBar()
image_path = "D:\\wamp\\www\\holdem\\src\\poker\\th\\images\\As.png"
myPicture = ImageIcon(image_path)
myPictureLabel = JLabel("Pocket: ", myPicture, JLabel.LEFT)
cardPanel = JPanel()
cardPanel.setLayout(None)
cardPanel.add(myPictureLabel)
myPictureLabel.setBounds(10,10,36,52);
self._frame.getContentPane().add(cardPanel)
self.msg=JLabel("Hello")
self._frame.add(self.msg, NORTH)
self._frame.locationRelativeTo = None
self._frame.visible = True
示例6: run
# 需要导入模块: from javax.swing import JFrame [as 别名]
# 或者: from javax.swing.JFrame import setJMenuBar [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()
示例7: __init__
# 需要导入模块: from javax.swing import JFrame [as 别名]
# 或者: from javax.swing.JFrame import setJMenuBar [as 别名]
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)
#.........这里部分代码省略.........