import javax.swing.*;
class First{
public static void main(String args[]){
Second gui = new Second();
gui.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
gui.setSize(425, 150);
gui.setVisible(true);
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.Formatter;
import java.util.Scanner;
public class Second extends JFrame {
private JButton b;
private Color color = Color.WHITE;
private JPanel panel;
public Second(){
super("Title");
panel = new JPanel();
panel.setBackground(color);
b = new JButton("Choose a color");
b.addActionListener(
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
color = JColorChooser.showDialog(null, "Choose a color", color);
panel.setBackground(color);
}
}
);
add(panel, BorderLayout.CENTER);
add(b, BorderLayout.SOUTH);
}
}