Guest User

Untitled

a guest
Jan 12th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. import javax.swing.*;
  2.  
  3. import BlackJack.Quit;
  4.  
  5. import java.awt.*;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8.  
  9.  
  10. public class lol2 extends JFrame
  11. {
  12. // Creating the components + global variables
  13.  
  14. //Creating the imageicon array
  15. JButton DealButton = new JButton ("Deal");
  16. ImageIcon[] ImageArray = new ImageIcon[52];
  17. JLabel picture = new JLabel();
  18. JPanel PlayerPanel = new JPanel();
  19. JPanel DealerPanel = new JPanel();
  20.  
  21. //Creating the constructor for the class
  22. public lol2()
  23. {
  24.  
  25. // Create the window
  26. super("Combo Box");
  27. setSize(400,350);
  28. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  29. //Set background Colour to custom RGB value
  30. setBackground(new Color(0, 139, 69));
  31.  
  32. DealerPanel.setLayout(new GridLayout(10,2));
  33. PlayerPanel.setLayout(new GridLayout(3,2));
  34.  
  35. // Load the array of images
  36. for(int i=0;i<52;i++){
  37. ImageArray[i] = new ImageIcon("resources/images/cards/"+i+".gif");
  38. }
  39.  
  40. //Add the components
  41. DealerPanel.add(DealButton);
  42. PlayerPanel.add(picture);
  43. add(DealerPanel);
  44. add(PlayerPanel);
  45.  
  46.  
  47.  
  48. //Add action listeners
  49. DealButton.addActionListener(new Deal());
  50. Container content = getContentPane();
  51.  
  52.  
  53.  
  54.  
  55. setVisible(true);
  56. }
  57.  
  58. class Deal implements ActionListener{
  59. public void actionPerformed(ActionEvent Dealing)
  60. {
  61. picture.setIcon(ImageArray[(int) Math.round(Math.random()*(ImageArray.length-1))]);
  62. }
  63.  
  64. }
  65.  
  66. public static void main (String[] args)
  67. {
  68. //Creating an instance of my class
  69. new lol2();
  70. }
  71.  
  72. }
Add Comment
Please, Sign In to add comment