Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. import javax.swing.JFrame;
  2. import java.util.Random;
  3. import java.awt.FlowLayout;
  4. import java.awt.Color;
  5. import java.awt.BorderLayout;
  6. import javax.swing.JPanel;
  7.  
  8.  
  9.  
  10. import javax.swing.JButton;
  11. import java.awt.event.ActionEvent;
  12. import java.awt.event.ActionListener;
  13.  
  14.  
  15.  
  16. public class Main {
  17.  
  18. private JFrame guiFrame = new JFrame();
  19. private ColorLabel[] arrayLabels = new ColorLabel[64];
  20. private Random rand = new Random();
  21.  
  22. public void createGUI() {
  23. guiFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  24. guiFrame.setTitle("Label demo");
  25. guiFrame.setLayout(new BorderLayout(2,2));
  26.  
  27. JPanel coloursPanel = new JPanel();
  28. coloursPanel.setLayout(new FlowLayout());
  29. for (int count=0; count < 64; count++) {
  30. Color labelColor = new Color(
  31. rand.nextInt(256),
  32. rand.nextInt(256),
  33. rand.nextInt(256)
  34. );
  35. arrayLabels[count] = new ColorLabel(64, 64, labelColor);
  36. coloursPanel.add(arrayLabels[count]);
  37. }
  38. guiFrame.add(coloursPanel, BorderLayout.CENTER);
  39.  
  40.  
  41. JButton refreshButton = new JButton("Press me to refresh labels");
  42.  
  43. guiFrame.add(refreshButton, BorderLayout.SOUTH);
  44.  
  45. guiFrame.pack();
  46. guiFrame.setVisible(true);
  47.  
  48.  
  49. refreshButton.addActionListener(new buttonPressed());
  50.  
  51. class buttonPressed implements ActionListener
  52. {
  53. @Override
  54. public void actionPerformed(ActionEvent e)
  55. {
  56.  
  57. }
  58. }
  59.  
  60.  
  61. }
  62.  
  63. public static void main(String[] args)
  64. {
  65. Main m = new Main();
  66. m.createGUI();
  67. }
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement