我正在尝试为我的GUI创建多个类(面板,框架,按钮......)。但是我无法将按钮类调用到我的框架中。
FrameLife
public class FrameLife extends JFrame implements MouseListener, ActionListener {
boolean [][]cells= new boolean [10][10];
JFrame frame= new JFrame("Conway's Game of Life");
panel mypanel1= new panel(cells);
Container b= new Buttons();
public FrameLife() {
frame.setSize(600, 600);
frame.setLayout(new BorderLayout());
frame.add(mypanel1, BorderLayout.CENTER);
b.setLayout(new GridLayout(1,3));
frame.add(b, BorderLayout.SOUTH);
mypanel1.addMouseListener(this);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
Buttons
public class Buttons {
boolean running=false;
public static Container south= new Container();
public static JButton reset= new JButton("Reset");
public static JButton start= new JButton("Start");
public static JButton pause= new JButton("Pause");
public Container Buttons(){
south.add(reset);
south.add(start);
south.add(pause);
return south;
}
}