public static JMenuBar initMenu ( ) { // show a menu JMenuBar menu = new JMenuBar ( ) ; JMenu file = new JMenu ( "File" ) ; file . getAccessibleContext ( ) . setAccessibleDescription ( "File Menu" ) ; JMenuItem openI = new JMenuItem ( "Open" ) ; openI . setMnemonic ( KeyEvent . VK_O ) ; openI . addActionListener ( new ActionListener ( ) { @ Override public void actionPerformed ( ActionEvent e ) { String cmd = e . getActionCommand ( ) ; if ( cmd . equals ( "Open" ) ) { final JFileChooser fc = new JFileChooser ( ) ; // In response to a button click: int returnVal = fc . showOpenDialog ( null ) ; if ( returnVal == JFileChooser . APPROVE_OPTION ) { File file = fc . getSelectedFile ( ) ; PDBFileReader reader = new PDBFileReader ( ) ; try { Structure s = reader . getStructure ( file ) ; BiojavaJmol jmol = new BiojavaJmol ( ) ; jmol . setStructure ( s ) ; jmol . evalString ( "select * ; color chain;" ) ; jmol . evalString ( "select *; spacefill off; wireframe off; backbone 0.4; " ) ; } catch ( Exception ex ) { ex . printStackTrace ( ) ; } } } } } ) ; file . add ( openI ) ; JMenuItem exitI = new JMenuItem ( "Exit" ) ; exitI . setMnemonic ( KeyEvent . VK_X ) ; exitI . addActionListener ( new ActionListener ( ) { @ Override public void actionPerformed ( ActionEvent e ) { String cmd = e . getActionCommand ( ) ; if ( cmd . equals ( "Exit" ) ) { System . exit ( 0 ) ; } } } ) ; file . add ( exitI ) ; menu . add ( file ) ; JMenu align = new JMenu ( "Align" ) ; JMenuItem pairI = new JMenuItem ( "2 protein structures" ) ; pairI . addActionListener ( new ActionListener ( ) { @ Override public void actionPerformed ( ActionEvent e ) { String cmd = e . getActionCommand ( ) ; if ( cmd . equals ( "2 protein structures" ) ) { MenuCreator . showPairDialog ( ) ; } } } ) ; align . add ( pairI ) ; menu . add ( align ) ; JMenu about = new JMenu ( "About" ) ; JMenuItem aboutI = new JMenuItem ( "PDBview" ) ; aboutI . addActionListener ( new ActionListener ( ) { @ Override public void actionPerformed ( ActionEvent e ) { String cmd = e . getActionCommand ( ) ; if ( cmd . equals ( "PDBview" ) ) { MenuCreator . showAboutDialog ( ) ; } } } ) ; about . add ( aboutI ) ; menu . add ( Box . createGlue ( ) ) ; menu . add ( about ) ; return menu ; }
provide a JMenuBar that can be added to a JFrame