Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- public class JConcentration
- {
- private JFrame frame;
- private JPanel panel;
- public static void main(String[] args)
- {
- new JConcentration();
- }
- public JConcentration()
- {
- this.frame = new JFrame();
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- this.panel = new JPanel(new GridLayout(4,5));
- addButtons();
- frame.getContentPane().add(panel);
- frame.setSize(600,600);
- frame.setVisible(true);
- }
- public void addButtons()
- {
- for(int i = 0; i < 20; i++)
- {
- JButton button = new Card();
- Card.button.setBackground(Color.red);
- Card.button.setActionListener(e ->
- { button.setText("5");
- });
- this.panel.add(button);
- }
- }
- class Card{
- private int number;
- private JButton button;
- public Card(int number)
- {
- this.number = number;
- this.button = new JButton();
- this.button.setBackground(Color.red);
- }
- public final int getNumber()
- {
- return number;
- }
- public final JButton getButton()
- {
- return button;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement