Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7731909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:35:55+00:00 2026-06-01T06:35:55+00:00

I’m having trouble; I’m trying to implement a cinema booking system however I cannot

  • 0

I’m having trouble; I’m trying to implement a cinema booking system however I cannot set an actionListener to a specific button on different grids. The way I want it to work is each user will have a session in which he can pick seats and a ticket price such as student rate, old age pensionate rates. Anyway, I cannot seem to be able to add actionListener, so when he picks seats, those become unavailable while the program is running. Thank you.

// Load Libraries
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class cinemaSystem {
    // Global Variables
    JFrame frame = new JFrame(); // Creates JFrame
    JLabel title;
    JButton l[][], m[][], r[][]; // Names grid of JButtons
    JPanel panel1, panel2, panel3;

    // Constructor
    public cinemaSystem(){

            title = new JLabel("Cinema Booking");
            title.setFont(new Font("Helvetica", Font.BOLD, 30));
            title.setLocation(12,5);
            title.setSize(600, 60);

            frame.setLayout(null); // Setting Grid Layout
            // panel1.setLayout(new GridLayout(seat,row));
            l = new JButton[4][4]; // Allocating Size of Grid
            panel1 = new JPanel(new GridLayout(4,4));
            panel1.setBackground(Color.black);
            panel1.setBounds(20, 70, 200, 140);
            for(int y = 0; y <4 ; y++){
                    for(int x = 0; x < 4; x++){
                        l[x][y] = new JButton("L" + y + x); // Creates New JButton
                        // l[x][y].addActionListener(this);
                        panel1.add(l[x][y]); //adds button to grid
                    }
            }

            m = new JButton[4][2]; // Allocating Size of Grid
            panel2 = new JPanel(new GridLayout(2,4));
            panel2.setBackground(Color.black);
            panel2.setBounds(240, 140, 200, 70);
            for(int y = 0; y <2 ; y++){
                    for(int x = 0; x < 4; x++){
                        m[x][y] = new JButton("M" + y + x); // Creates New JButton
                        panel2.add(m[x][y]); //adds button to grid
                    }
            }

            r = new JButton[4][4]; // Allocating Size of Grid
            panel3 = new JPanel(new GridLayout(4,4));
            panel3.setBackground(Color.black);
            panel3.setBounds(460, 70, 200, 140);
            for(int y = 0; y <4 ; y++){
                    for(int x = 0; x < 4; x++){
                        r[x][y] = new JButton("R" + y + x); // Creates New JButton
                        panel3.add(r[x][y]); //adds button to grid
                    }
            }

            frame.add(title);
            frame.add(panel1);
            frame.add(panel2);
            frame.add(panel3);
            frame.setPreferredSize(new Dimension(680, 280));
            frame.setTitle("Cinema Booking");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack(); //sets appropriate size for frame
            frame.setVisible(true); //makes frame visible
    }

    // Main Class
    public static void main(String[] args) {
            new cinemaSystem(); //makes new ButtonGrid with 2 parameters
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T06:35:57+00:00Added an answer on June 1, 2026 at 6:35 am

    You can get the text held by the pressed JButton simply by calling getActionCommand() on the ActionEvent object passed into the actionPerformed(...) method, or you can get which button was pressed via its getSource() method. Either of these can help you find the JButton in your arrays and inactivate it.

    Other suggestions:

    • Don’t use this as your ActionListener. Instead consider using an anonymous inner class or private inner class. This will make your code much more flexible and your ActionListeners much simpler.
    • Try to follow Java naming conventions including being sure that class names start with capital letters and that variables and method names begin with lower-case letters. This will make it much easier for others (such as us!) to be able to understand your code at a glance.
    • Avoid use of absolute layouts as it makes your GUI’s hard to maintain and doesn’t allow your GUI’s to re-size flexibly for different OS’s or screen resolutions. For instance your current GUI looks like this on my screen:

    enter image description here

    For example this ActionListener will show which button was pressed and will inactivate that button:

    private class MyListener implements ActionListener {
      public void actionPerformed(ActionEvent e) {
         System.out.println("Button pressed: " + e.getActionCommand());
         ((JButton)e.getSource()).setEnabled(false);
      }
    }
    

    Which can be added to the JButtons in a fashion similar to this…

      ActionListener listener = new MyListener();
    
      for (int i = 0; i < leftBtns.length; i++) {
         for (int j = 0; j < leftBtns[i].length; j++) {
            JButton btn = new JButton("L" + i + j);
            btn.setFont(btn.getFont().deriveFont(Font.BOLD, BTN_FONT_SIZE));
            btn.addActionListener(listener);
            leftPanel.add(btn);
         }
      }
    

    Plus using appropriate layout managers produced a GUI that looked like this:
    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.