@Override
public void actionPerformed(ActionEvent e) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600,600);
frame.setVisible(true);
frame.setLayout(new BorderLayout(25,0));
int r;
int g;
int b;
Random rand = new Random();
r = rand.nextInt(255);
g = rand.nextInt(255);
b = rand.nextInt(255);
Color c1 = new Color(r,g,b);
Color c2 = new Color(r,g,b);
Color c3 = new Color(r,g,b);
JPanel panel = new JPanel();
panel.setBackground(c1);
panel.setPreferredSize(new Dimension(200,200));
frame.add(panel, BorderLayout.EAST);
JPanel panel1 = new JPanel();
panel.setBackground(Color.BLACK);
panel1.setPreferredSize(new Dimension(200,200));
frame.add(panel1, BorderLayout.WEST);
JPanel panel2 = new JPanel();
panel.setBackground(Color.gray);
panel2.setPreferredSize(new Dimension(200,200));
frame.add(panel2, BorderLayout.CENTER);
}
}
When this action is performed, it only shows one of the colors in a separate window, when I wanted all three of the colors to be shown, side by side, and fill up the entire window with the three panels.
New contributor
Tyree M. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.