Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.36 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3.  
  4.  
  5. public class JConcentration
  6. {
  7.     private JFrame frame;
  8.     private JPanel panel;
  9.  
  10.     public static void main(String[] args)
  11.         {
  12.          new JConcentration();
  13.         }
  14.  
  15.     public JConcentration()
  16.     {
  17.         this.frame = new JFrame();
  18.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  19.         this.panel = new JPanel(new GridLayout(4,5));
  20.         addButtons();
  21.         frame.getContentPane().add(panel);
  22.         frame.setSize(600,600);
  23.         frame.setVisible(true);
  24.     }
  25.  
  26.     public void addButtons()
  27.     {
  28.         for(int i = 0; i < 20; i++)
  29.         {
  30.             JButton button = new Card();
  31.             Card.button.setBackground(Color.red);
  32.             Card.button.setActionListener(e ->
  33.             { button.setText("5");
  34.             });
  35.             this.panel.add(button);
  36.         }
  37.     }
  38.    
  39.     class Card{
  40.          private int number;
  41.                 private JButton button;
  42.        
  43.                 public Card(int number)
  44.                 {
  45.                     this.number = number;
  46.                     this.button = new JButton();
  47.                     this.button.setBackground(Color.red);
  48.                 }
  49.        
  50.                 public final int getNumber()
  51.                 {
  52.                     return number;
  53.                 }
  54.        
  55.                 public final JButton getButton()
  56.                 {
  57.                     return button;
  58.                 }
  59.    
  60.         }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement