public class ListColor extends JFrame {
Color[] farby = {Color.RED, Color.YELLOW, Color.BLUE, Color.GRAY, Color.GREEN, Color.ORANGE, Color.BLACK};
private JPanel contentPane;
private JPanel panel;
private JPanel panel_1;
private JPanel panel_2;
private JPanel panel_3;
private JPanel panel_4;
private JPanel panel_5;
private JPanel panel_6;
private JButton btnNakresli;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ListColor frame = new ListColor();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public ListColor() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JButton btnNakresli = new JButton("Nakresli");
btnNakresli.setBounds(298, 129, 89, 23);
contentPane.add(btnNakresli);
JButton btnPosun = new JButton("Posun");
btnPosun.setBounds(298, 163, 89, 23);
contentPane.add(btnPosun);
JPanel panel = new JPanel();
panel.setBounds(37, 48, 50, 50);
contentPane.add(panel);
JPanel panel_1 = new JPanel();
panel_1.setBounds(87, 48, 50, 50);
contentPane.add(panel_1);
JPanel panel_2 = new JPanel();
panel_2.setBounds(137, 48, 50, 50);
contentPane.add(panel_2);
JPanel panel_3 = new JPanel();
panel_3.setBounds(187, 48, 50, 50);
contentPane.add(panel_3);
JPanel panel_4 = new JPanel();
panel_4.setBounds(237, 48, 50, 50);
contentPane.add(panel_4);
JPanel panel_5 = new JPanel();
panel_5.setBounds(287, 48, 50, 50);
contentPane.add(panel_5);
JPanel panel_6 = new JPanel();
panel_6.setBounds(337, 48, 50, 50);
contentPane.add(panel_6);
btnNakresli.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
panel.setBackground(farby[0]);
panel_1.setBackground(farby[1]);
panel_2.setBackground(farby[2]);
panel_3.setBackground(farby[3]);
panel_4.setBackground(farby[4]);
panel_5.setBackground(farby[5]);
panel_6.setBackground(farby[6]);
}
});
btnPosun.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Color temp = farby[6];
for (int i = farby.length-1; i>0; i--) {
farby[i] = farby [i-1];
}
farby[0] = temp;
}
});
}
}