I'm looking at a GUI program made using MVC and they have this method. What does this method do and when will you need to use it?
attach(this);
Here is one of the classes with the method.
import model.*;
import java.awt.*;
import java.text.*;
import javax.swing.*;
public class IncomePanel extends JPanel implements View
{ private Stadium stadium;
private JLabel label;
public IncomePanel(Stadium stadium)
{ this.stadium = stadium;
for (Group group: stadium.seats())
group.attach(this);
setup();
build(); }
private void setup()
{ setBorder(BorderFactory.createLineBorder(Color.blue));
setLayout(new FlowLayout()); }
private void build()
{ label = new JLabel(income());
label.setForeground(Color.blue);
add(label); }
public void update()
{ label.setText(income()); }
private String income()
{ return "Income is $" + twoDec(stadium.income()); }
private String twoDec(double value)
{ DecimalFormat twoD = new DecimalFormat("#0.00");
return twoD.format(value); }
}