What\'s the difference between:
public class Test {
public static void main(String[] args) {
JButton button= new JButton(\"1\");
button.
You can use a JPanel
to create a reusable building block of your user interface and maintain a single point of maintenance for all instances of it. Let's say you would create a JFrame
containing a diff view for two texts. The left and right view are lets say identical twins. It is way easier to create a panel twice and to add these two panels on the frame instead of adding all subsequent components twice into your frame directly.
Whenever you now have to change the view, let's say you want to add another button, or whatever you can do it at your panel and both - the left and right view will contain the changes immediately.