| |

VerySource

 Forgot password?
 Register
Search
View: 1065|Reply: 7

super doubt

[Copy link]

2

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-23 13:30:01
| Show all posts |Read mode
public class RoundButton extends JButton {
    
    public RoundButton (String label) {
        super (label); // What does super mean here?

Dimension size = getPreferredSize ()
setPreferredSize (size); // Do these two sentences not repeat?
Reply

Use magic Report

2

Threads

12

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-7-3 00:00:01
| Show all posts
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.
Reply

Use magic Report

0

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-7-6 02:30:01
| Show all posts
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
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-7-6 09:45:01
| Show all posts
Lou Lou read the book to make up for the foundation
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-7-10 10:45:01
| Show all posts
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?
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-7-11 11:30:01
| Show all posts
extends does not inherit the constructor. You must write your own code! super(label); call the constructor of the parent class!
Reply

Use magic Report

2

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-7-16 13:45:02
| Show all posts
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?
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-7-17 14:30:01
| Show all posts
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.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list