Learn the Java object construction process through examples-Linux general technology-Linux programming and kernel information. The following is a detailed description. This article provides an example of errors in a Project, provides observation and analysis, reveals the specific process of Java language instantiating an object, and finally summarizes an important rule for designing a Java class. By reading this article, Java programmers can understand the Java object construction process and design more robust code. This article is suitable for Java beginners and Java programmers who need to improve reading.
The program throws an exception.
The author once provided an abstract dialog box base class to project team members in a project. Users only need to implement an abstract method of the base class in the subclass to draw an interface for displaying data, so that the dialog box in the project has the same style. The specific code implementation snippets are as follows (other irrelevant codes are omitted for the sake of conciseness ):
CODE: public abstract class BaseDlg extends JDialog { Public BaseDlg (Frame frame, String title ){ Super (frame, title, true ); This. getContentPane (). setLayout (new BorderLayout ()); This. getContentPane (). add (createHeadPanel (), BorderLayout. NORTH ); This. getContentPane (). add (createClientPanel (), BorderLayout. CENTER ); This. getContentPane (). add (createButtonPanel (), BorderLayout. SOUTH ); }
Private JPanel createHeadPanel (){ ... // Create a dialog box Header }
// Create the customer region in the dialog box and hand it to the sub-class for implementation. Protected abstract JPanel createClientPanel ();
Private JPanel createButtonPanel { ... // Create button Area } } |