Reputation: 43047
I know that JFrame is a top level container fro Swing GUI and that I can put a JPanel object inside a JFrame object.
But also JPanel is a container...so what is the difference from JFrame and JPanel.
I see that, in the GUI implementation, is implement directly a JPanel object, other times I see that is implemented a JFrame in which I put a JPanel.
What is the difference?
Tnx
Andrea
Upvotes: 1
Views: 307
Reputation: 685
Upvotes: 2
Reputation: 864
Basically, a JFrame represents a framed window and a JPanel represents some area in which controls (e.g., buttons, checkboxes, and textfields) and visuals (e.g., figures, pictures, and even text) can appear.
JPanel serves as a general purpose container, while JFrame is a window commonly used for stand-alone applications, like a warning window, or a notification window.
Upvotes: 1
Reputation: 30678
JFrame - Used to represent the features a like a window. This includes border,titlebar, different controls, and different event handlers. refer : http://docs.oracle.com/javase/6/docs/api/javax/swing/JFrame.html
JPanel - Most Generic class used as a container to gather other elements together. This is more important with working with the visual layout or one of the provided layout managers. refer : http://docs.oracle.com/javase/6/docs/api/javax/swing/JPanel.html
EDIT: Some more
Upvotes: 5
Reputation: 626
A JFrame rappresent a window, the jpanel is a part of the gui contained in a window.
http://docs.oracle.com/javase/tutorial/uiswing/components/frame.html
http://docs.oracle.com/javase/tutorial/uiswing/components/panel.html
Upvotes: 3