Interested in this question: I create in one class JFrame , in another, for example, JMenuBar . I also create a variable of this class in a class with a JFrame , but the menu bar does not appear.
That's interesting, is it possible to do that? If necessary? Simply, it is more convenient to edit components when necessary. Roughly speaking, it looks like this:

 public class MyFrame extends JFrame{ private MyMenuBar menuBar; public MyFrame(){ // описываем класс } menuBar = new MyMenuBar(); setJMenuBar(menubar); } public class MyMenuBar extends JMenuBar{ public MyMenuBar(){ // описываем класс } } 
  • understand the principle of working and building classes, libraries, etc. in Java, you must understand that everything in Java are objects that can be redefined, another thing is that it is not always necessary to do this. I answer the questions, you can do it, you can do this here, if you are not going to write your menu bar, in this case you will only complicate the code - Gorets
  • that is, it turns out that all the necessary components and their listeners are better written in the MyFrame class? - Kobayashi_Maru
  • Yes, MyFrame - will be like a container, store listeners, and already processing them, if it is complicated - can be better displayed in separate classes - Gorets
  • thank you =) - Kobayashi_Maru

1 answer 1

 menuBar = new MyMenuBar(); setJMenuBar(mymenubar); 

find 10 differences

  • ochepyatka, it happens ... but that's not the point ... - Kobayashi_Maru