Question
LiteBrite.java and LiteBritePanel.java are provided below Use the existing LiteBrite driver class and LiteBritePanel class. Write LiteBriteBoardPanel and LitePegButton classes The LiteBrite driver class is
LiteBrite.java and LiteBritePanel.java are provided below
Use the existing LiteBrite driver class and LiteBritePanel class.
Write LiteBriteBoardPanel and LitePegButton classes
The LiteBrite driver class is already complete. It creates a new JFrame and adds a LiteBritePanel to the frame.
The LiteBriteBoardPanel class is mostly complete, you will just need to add a second ActionListener to handle LitePegButton clicks. It extends JPanel, which means it is a JPanel. It will not compile until you implement your LiteBriteBoardPanel and LitePegButton classes.
LiteBriteBoardPanel and LitePegButton classes
Create classes for LitePegButton and LiteBriteBoardPanel.
LitePegButton must extend JButton. It will represent the state of a single peg button. Implement the methods as shown in the class design image below.
LiteBriteBoardPanel must extend JPanel. It will represent the state of the entire board. Implement the methods as shown in the class design below.
Here are a few images to help you visualize the classes you will be implementing and the GUI components you will be adding. The Lite-Brite GUI Layout. The Lite-Brite Class Design. You must implement all the instance variables/methods described.
//LiteBrite.java (file1)
import javax.swing.JFrame;
/**
* Represents a LiteBrite game board GUI.
*
*
*/
public class LiteBrite
{
/**
* Creates a JFrame and adds the main JPanel to the JFrame.
* @param args (unused)
*/
public static void main(String args[])
{
JFrame frame = new JFrame("Lite Brite");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new LiteBritePanel(20, 20));
frame.pack();
frame.setVisible(true);
}
}
//LiteBritePanel.java (file2)
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JPanel;
@SuppressWarnings("serial")
public class LiteBritePanel extends JPanel
{
private LiteBriteBoardPanel board;
private JButton resetButton;
/**
* Creates a new LiteBrite GUI with specified width and height.
* @param width The number of pegs in the horizontal axis.
* @param height The number of pegs in the vertical axis.
*/
public LiteBritePanel(int width, int height)
{
// Create new LiteBriteBoard with specified dimensions
board = new LiteBriteBoardPanel(new LitePegListener(), width, height);
// Create reset button and add ActionListener to it.
resetButton = new JButton("Reset");
resetButton.addActionListener(new ResetButtonListener());
// Add sub-components to this main panel.
this.add(board);
this.add(resetButton);
}
/**
* The ActionListener for the button to reset the game.
*/
private class ResetButtonListener implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e)
{
board.reset();
}
}
/**
* TODO: Implement the ActionListener for the button representing a peg.
* Changes the color of the peg when the button is clicked.
*/
private class LitPegButton implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e)
{
//TODO
}
}
}
Lite Brite Reset The Lite-Brite GUIStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started