import [Link].
*;
import [Link].*;
import [Link].*;
public class ColorPalette extends JFrame implements ActionListener {
private JTextField textField;
private JPanel colorPanel;
private JRadioButton backgroundRadio;
private JRadioButton foregroundRadio;
public ColorPalette() {
// Set the BorderLayout for the frame
setLayout(new BorderLayout());
// Create and place the text field in the north
textField = new JTextField("Sample Text");
add(textField, [Link]);
// Create and configure the panel with GridLayout
colorPanel = new JPanel();
[Link](new GridLayout(5, 5));
// Create an array of colors for buttons
Color[] buttonColors = {
[Link], [Link], [Link], [Link], [Link],
[Link], [Link], [Link], Color.LIGHT_GRAY, Color.DARK_GRAY,
[Link], [Link], [Link], Color.LIGHT_GRAY, Color.DARK_GRAY,
[Link], [Link], [Link], [Link], [Link],
[Link], [Link], [Link], [Link], [Link]
};
// Create buttons with unique colors and add them to the panel
for (Color color : buttonColors) {
JButton button = new JButton();
[Link](color);
[Link](this);
[Link](button);
// Place the panel in the center of the applet
add(colorPanel, [Link]);
// Create radio buttons for Background and Foreground
backgroundRadio = new JRadioButton("Background");
foregroundRadio = new JRadioButton("Foreground");
// Create a ButtonGroup for radio buttons
ButtonGroup radioGroup = new ButtonGroup();
[Link](backgroundRadio);
[Link](foregroundRadio);
// Add radio buttons to the south
JPanel radioPanel = new JPanel();
[Link](backgroundRadio);
[Link](foregroundRadio);
add(radioPanel, [Link]);
// Set default radio selection
[Link](true);
// Set frame properties
setTitle("Color Palette");
setSize(400, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
public void actionPerformed(ActionEvent e) {
Color buttonColor = ((JButton) [Link]()).getBackground();
if ([Link]()) {
[Link](buttonColor);
} else if ([Link]()) {
[Link](buttonColor);
public static void main(String[] args) {
[Link](new Runnable() {
public void run() {
new ColorPalette();
});