Does that sound normal?



  • public class MainTest {
        PracticeWork1 grades;
    
        MainTest() {
            grades = new PracticeWork1();
            init();
        }
    
        public static void main(String[] args) {
            new MainTest();
        }
    
        public void init() {
            testOut();
            grades.adder();
            testOut();
            grades.adder(98);
            testOut();
        }
    }
    

    Example 2

    public class MyWin extends JFrame {
    
    private static final long serialVersionUID = 1L;
    
    public MyWin() {
        Container c = getContentPane(); 
        c.setLayout(new BorderLayout()); 
    
        Panel child= new Panel();    
        c.add(child);
        setTitle("Example window"); 
    
        setPreferredSize(new Dimension(640, 480));
    
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
        setVisible(true); // отображаем окно
    }
    
    public static void main(String args[]) {
        new MyWin();
    }
    

    }

    Is it right in the main method to create an encryption of the class in which this mein is located rather than to prescribe most of the logic in it?



  • If I understood your question correctly, he'd be able to put the class logic in the designer.

    Technically, it might work, but in terms of the meaning of the code, it's not very good. The designer shall design Class and action to be launched by

    If your project is small, you can break this rule (as many others) but for a more serious project, I would advise that only initialization be left to the designer.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2