1

This is probably a stupid question but i have been searching for the answere all day know, and i can't find it.

I'm following a Java course on an University and when i create new JFrame ( only create by typing in a name and klik create) the code does not look the same as in the course. I get a main method and in the course they get a default constructor.

i get:

   /**
   * Launch the application.
   */
  public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
      public void run() {
        try {
          jkksl frame = new jkksl();
          frame.setVisible(true);
        }
        catch (Exception e) {
          e.printStackTrace();
        }
      }
    });
  }

  /**
   * Create the frame.
   */
  public jkksl() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 450, 300);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(new BorderLayout(0, 0));
    setContentPane(contentPane);
  }

It creates a public static void main() automatically, but when they do the same in the course (only create a new JFrame), the basic code they get is:

  private static final long serialVersionUID = 1L;
  private JPanel jContentPane = null;

  /**
   * This is the default constructor
   */
  public variabelveld2() {
    super();
    initialize();
  }

  /**
   * This method initializes this
   * 
   * @return void
   */
  private void initialize() {
    this.setSize(300, 200);
    this.setContentPane(getJContentPane());
    this.setTitle("JFrame");
  }

  /**
   * This method initializes jContentPane
   * 
   * @return javax.swing.JPanel
   */
  private JPanel getJContentPane() {
    if (jContentPane == null) {
      jContentPane = new JPanel();
      jContentPane.setLayout(new BorderLayout());
    }
    return jContentPane;
  }

When only creating a JFrame, so not typing in any code, the code doesn't have a main and does get a default constructor with super() and initialize().

I can't seem to find why they get the default constructor and i get a main method and how i can change the settings so i also get a default constructor with super() and initialize().

Can someone please help?

cchamberlain
  • 17,444
  • 7
  • 59
  • 72
Vera
  • 11
  • 2
  • are you extending JFrame? if yes why you don't call super()? – XtremeBaumer Dec 19 '16 at 14:00
  • Oke im a noob sorry, but all i did is create a new JFrame by selecting the package and create a new JFrame – Vera Dec 19 '16 at 14:01
  • When they do this in the course it opens automatically with the second code but i get the first code – Vera Dec 19 '16 at 14:03
  • Are you talking about the look and feel of the frame? Like a Windows or Mac look? – Luke Melaia Dec 19 '16 at 14:03
  • No, i really mean the content of the code. Mine has a main with public void run{ and the other one has super() and initialize(); – Vera Dec 19 '16 at 14:06
  • First of all, this isn't a default constructor. The secondly do you use any plugin to generate that code? A can remember using a WindowBuilder plugin, which generated the Swing code. Maybe you're using a different one (or a different version) than the others? – Tom Dec 19 '16 at 15:10
  • In thought so but in the comments above the code it said // generates default constructor, does it have a different name? Because i probably can find information when i have the right name. Yes we use a window builder plugin. It should be the same version, but to me its a big difference, im a seeing that wrong? – Vera Dec 19 '16 at 15:33
  • ["Difference between a no-arg constructor and a default constructor in Java"](http://stackoverflow.com/questions/27654167/difference-between-a-no-arg-constructor-and-a-default-constructor-in-java) ... *"It should be the same version, but to me its a big difference, im a seeing that wrong?"* Well, not a big difference, more like a matter of style. There might be a setting to decided which style you want. Something like "generate 'initialize' methode". – Tom Dec 19 '16 at 15:39
  • Yes there is! But this already stands on initialize: Window Builder > Swing > Code generation: Method name for new statements : initialize. I already tried to restore it to default and change to initialize again but it makes no difference in the generated code.. – Vera Dec 19 '16 at 15:43
  • *"in the generated code"* The code is already there, so any change in that setting should only affect new code. So try to create a new GUI while this setting is on. – Tom Dec 19 '16 at 15:51
  • I still get the same code.. i already tried to completely reinstall everything but it still gives the same code – Vera Dec 19 '16 at 15:59
  • Maybe I'm a bit slow today, and apologize the rather broad question: What are you talking about? Is this some about some GUI-Building-Tool? Something that is part of Eclipse or NetBeans or IntelliJ? You should add the appropriate tags in this case. In any case, I can imagine that the *code templates* that are used by these GUI-Building-Tools occasionally change between different versions. – Marco13 Dec 19 '16 at 18:28

0 Answers0