Re: method for a class constructor
This is what your code should look like
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Test extends JFrame { // Class names should begin with a
capital letter
Alpha alpha = null; // Alpha is spelled with a 'ph', not 'f'
Beta beta = null; // although not required, you should always
initialize all variables
Gamma gamma = null; // instance names should begin with a lowercase
letter
public Test () {
alpha = new Alpha(this, null);
beta = new Beta(this, null, null);
gamma = new Gamma(this, null);
alpha.setBeta(beta); // method names should begin with a lowercase
letter, but capitalize all other words.
beta.setAlpha(alpha);
beta.setGamma(gamma);
gamma.setBeta(beta);
}
}
class Alpha extends JPanel implements ActionListener {
Test test = null;
Beta beta = null;
public Alpha(Test test, Beta beta) {
this.test = test;
this.beta = beta;
}
public void setBeta(Beta beta) {
this.beta = beta;
}
public void actionPerformed(ActionEvent actionEvent) {
// this method is here because this class implements
ActionListener
}
}
class Beta extends JPanel implements ActionListener {
Test test = null;
Alpha alpha = null;
Gamma gamma = null;
public Beta(Test test, Alpha alpha, Gamma gamma) {
this.gamma = gamma;
this.test = test;
this.alpha = alpha;
}
public void setAlpha(Alpha alpha) {
this.alpha = alpha;
}
public void setGamma(Gamma gamma) {
this.gamma = gamma;
}
public void actionPerformed(ActionEvent actionEvent) {
// this method is here because this class implements
ActionListener
}
}
class Gamma extends JPanel {
Test test = null;
Beta beta = null;
public Gamma(Test test, Beta beta) {
this.test = test;
this.beta = beta;
}
public void setBeta(Beta beta) {
this.beta = beta;
}
}