0

So I've two pseudocodes:

class A 
{
  JFrame sampleFrame = new JFrame();
  JPanel samplePanel = new JPanel();
  JButton sampleButton = new JButton("Click");
  //...

  A() 
  {
    // Other things like setting up ActionListeners, 
    // frame title/geometry etc. + others
  }
}
class B 
{
  JFrame sampleFrame;
  JPanel samplePanel;
  JButton sampleButton;
  //...

  B() 
  {
    sampleFrame = new JFrame();
    samplePanel = new JPanel();
    sampleButton = new JButton("Click");

    // Other things like setting up ActionListeners, 
    // frame title/geometry etc. + others
  }
}

Which one of these in the conventional/correct way of doing so?

I find B redundant when I can just initialize these JComponents when they are declared as field variables, but I've seen many code online mostly resembling B

0 Answers0