import java.awt.event.ActionListener;
import javax.swing.JFrame;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
/**
*/
public class LastManStanding extends JFrame implements ActionListener{
JCheckBox[] checkBoxes = new JCheckBox[10];
JButton turn = new JButton("Complete Turn");
JLabel header = new JLabel ("Please select 1, 2, or 3 boxes.");
JLabel footer = new JLabel ("Whoever selects the last box wins.");
Font headerFont = new Font("Century", Font.PLAIN, 15);
Font footerFont = new Font("Century", Font.PLAIN, 13);
public LastManStanding()
{
final int FRAME_WIDTH = 240;
final int FRAME_HEIGHT = 200;
JFrame gameFrame = new JFrame("Last Man Standing");
gameFrame.setBounds(600,400,FRAME_WIDTH, FRAME_HEIGHT);
header.setFont(headerFont);
footer.setFont(footerFont);
// a loop to create and modify
for (int i = 0; i < checkBoxes.length; i++)
{
checkBoxes[i] = new JCheckBox(String.valueOf(i + 1));
checkBoxes[i].addActionListener(this);
}
turn.addActionListener(this);
gameFrame.setLayout(new FlowLayout());
gameFrame.add(header);
for (JCheckBox checkBox: checkBoxes) // for-each loop
{
gameFrame.add(checkBox);
}
gameFrame.add(turn);
gameFrame.add(footer);
gameFrame.setVisible(true);
gameFrame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
}
public static void main(String[] args)
{
LastManStanding game = new LastManStanding();
System.out.println(game.getComponents());
}
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if(source instanceof JCheckBox)
{
((JCheckBox) source).setEnabled(false);
}
if (source instanceof JButton)
{
System.out.println("the button");
}
}
}