Please let me know that what's the component heirarchical structure, i.e, what comes first ...........window then applet or frame is pasted, then comes panel ,after that all GUIs. If I m wrong then plz tell. If I m right then also reply me, I am still confused. :confused:

Dani AI

Generated

Short answer (class versus containment): the GUI class inheritance tree starts at java.lang.Object -> java.awt.Component -> java.awt.Container -> javax.swing.JComponent, and concrete Swing classes such as JPanel, JButton and JLabel inherit from JComponent. Top-level windows (JFrame, JDialog, JWindow or the AWT Frame/Dialog/Window classes) are separate kinds of containers that serve as the root(s) of a component tree rather than children of JComponent. (docs.oracle.com)

That distinction answers the original confusion from : class hierarchy (who extends whom) is not the same as the containment (instance) hierarchy that actually places components on screen. A running GUI is a tree of component instances rooted in a top-level container; the content pane / root pane of a JFrame or JDialog holds intermediate containers (like JPanel) which hold atomic components (buttons, labels, etc.). See the Java Tutorial for the containment rules and examples. (docs.oracle.com)

Practical rule and quick example: construct and touch Swing components only on the Event Dispatch Thread (Swing is not thread safe). Create the window on the EDT and add panels/components to its content pane. Example pattern:

SwingUtilities.invokeLater(() -> {
    JFrame f = new JFrame("Demo");
    JPanel p = new JPanel();
    p.add(new JButton("OK"));
    f.getContentPane().add(p);
    f.pack();
    f.setVisible(true);
});

See Swing's threading policy for why invokeLater / SwingWorker is needed. (docs.oracle.com)

One important historical note: applets (java.applet.Applet and javax.swing.JApplet) used to be a top-level special case, but the Applet API has been deprecated for removal and is being removed from recent JDKs — migrate desktop code away from applets. For diagrams, ’s links were useful; and, as suggested, the Java Tutorials or a good Swing book are the right next step for a deeper, worked explanation. (docs.oracle.com)

Recommended Answers

All 2 Replies

Or just read a good book... We're not here to write your research papers for you, nor to find things for you to plagairise.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.