You should be getting a compile error, but "mb" is out of scope in main() and will be considered a null pointer at runtime. If you really want to do it the way you have set up, you have to extend JMenuBar in MainProg and then add it to the new JFrame.