Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JFrame;
- import java.util.Random;
- import java.awt.FlowLayout;
- import java.awt.Color;
- import java.awt.BorderLayout;
- import javax.swing.JPanel;
- import javax.swing.JButton;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- public class Main {
- private JFrame guiFrame = new JFrame();
- private ColorLabel[] arrayLabels = new ColorLabel[64];
- private Random rand = new Random();
- public void createGUI() {
- guiFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- guiFrame.setTitle("Label demo");
- guiFrame.setLayout(new BorderLayout(2,2));
- JPanel coloursPanel = new JPanel();
- coloursPanel.setLayout(new FlowLayout());
- for (int count=0; count < 64; count++) {
- Color labelColor = new Color(
- rand.nextInt(256),
- rand.nextInt(256),
- rand.nextInt(256)
- );
- arrayLabels[count] = new ColorLabel(64, 64, labelColor);
- coloursPanel.add(arrayLabels[count]);
- }
- guiFrame.add(coloursPanel, BorderLayout.CENTER);
- JButton refreshButton = new JButton("Press me to refresh labels");
- guiFrame.add(refreshButton, BorderLayout.SOUTH);
- guiFrame.pack();
- guiFrame.setVisible(true);
- refreshButton.addActionListener(new buttonPressed());
- class buttonPressed implements ActionListener
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- }
- }
- }
- public static void main(String[] args)
- {
- Main m = new Main();
- m.createGUI();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement