super(label)// is the constructor that calls the parent class (superclass).
As you can see from the method name, the purpose of getPreferredSize() is to return a value; and the role of setPreferredSize(size) is to set a value. It is obviously different.
1. In the constructor with parameters, the child class needs to explicitly call the Super() method to call the parent class constructor to implement the default function.
2. One is setter() and one is getter(). Two attributes of the field
super(label);//super here is to call the inherited JButton class, super means to call the closest to the parent class.
Dimension size = getPreferredSize()/*Because it inherits the JButton class. Therefore, the getPreferredSize() function inherited from the parent class is called to obtain the value of size, and then copied to the object of the current class, which is a concept of encapsulation
setPreferredSize(size);//Don't these two sentences repeat?
I am the landlord, what is the use of calling the parent class constructor here? Then, getPreferredSize() to get the value to size, and then set back with setPreferredSize(size), that is, take it out and send it back, what is the meaning What?
It may be to call the constructor of the parent class to set the name of the button.
Did not strictly abide by the javaBean specifications:
Dimension size = getPreferredSize()
The value of the attribute preferredSize is assigned to the member variable size;
getPreferredSize();
setPreferredSize(size);
Set the attribute preferredSize to be readable and writable.