Java Codesnippet: Create a Reservation Manager and give the user the possibility to reserve Seats

You can use the following JPanel as a starting point if you want to create a cinema application, which should give the user the opportunity to reserve seats by clicking on the nice JButton’s

01

02

03

04

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class ListButtonPanel extends JPanel implements ActionListener {

    private List buttons = new ArrayList<>();
    
    public ListButtonPanel() {
        
        this.setPreferredSize(new Dimension(1024, 768));
        for(int i = 1; i <= 100; i++) {
            buttons.add(new JButton("Seat-" + i));
        }
        
        this.setLayout(new GridLayout(10, 10));
        for(JButton button : buttons) {
            button.addActionListener(this);
            this.add(button);
        }
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        JButton sourceBtn = (JButton) e.getSource();
        
        int showConfirmDialog = JOptionPane.showConfirmDialog(getParent(), "You want to reserve seat " + sourceBtn.getText() + "", "Reserve Seat", JOptionPane.YES_NO_CANCEL_OPTION);
        
        if(showConfirmDialog == 0) {
            sourceBtn.setBorder(BorderFactory.createLineBorder(Color.RED, 3, true));
            sourceBtn.setEnabled(false);
            sourceBtn.setForeground(Color.red);
        }
    }
}