Update JLabel text - java

I'm working on a simple GUI. On Button press i want to increase/decrease a variable and update the corresponding JLabel.
class JFrameSetUp
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JFrameSetUp extends JFrame implements ActionListener {
private int RecHeight = 0;
private int RecWidth = 0;
//Here Buttons
JButton HeightIncrease = new JButton("+");
JButton HeightDecrease = new JButton("-");
JLabel height = new JLabel(Integer.toString(RecHeight));
JLabel width = new JLabel(Integer.toString(RecWidth));
GridLayout gridLayout = new GridLayout(2, 4);
public JFrameSetUp(){
}
public void addComponentsToPane(final Container pane){
//Create GridPanel and set Layout
JPanel grid = new JPanel();
grid.setLayout(gridLayout);
//Create buttondrawPanel and set Layout
JPanel buttondraw = new JPanel();
buttondraw.setLayout(new GridLayout(2, 0));
//Adding Components to GridPanel
//Adding Layouts to pane
pane.add(grid, BorderLayout.NORTH);
pane.add(new JSeparator(), BorderLayout.CENTER);
pane.add(buttondraw, BorderLayout.SOUTH);
}
#Override
public void actionPerformed(ActionEvent e) {
//Setting up ActionListener to Buttons
if (e.getSource() == this.HeightDecrease) {
RecHeight -= 1;
height.setText(Integer.toString(RecHeight));
} else if (e.getSource() == this.HeightIncrease) {
RecHeight += 1;
height.setText(Integer.toString(RecHeight));
}
}
}
Class with MainMethod
import javax.swing.JFrame;
public class Program {
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
private static void createAndShowGUI() {
//Create and set up the window.
JFrameSetUp frame = new JFrameSetUp();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Set up the content pane.
frame.addComponentsToPane(frame.getContentPane());
//Display the window.
frame.pack();
frame.setVisible(true);
}
}
I'm aware, that's kind a newbish question. I think I'm wrong with my Code Structure. Any help is appreciated.
Thanks in advance.

You never register any ActionListeners to the buttons...
HeightIncrease.addActionListener(this);
HeightDecrease.addActionListener(this);
You also never add the buttons to the GUI
buttondraw.add(HeightIncrease);
buttondraw.add(HeightDecrease);
You also never add the labels to the GUI either...
grid.add(height);
grid.add(width);
I reworked the code, because your example was messing with my mind, hope you don't mind...
It's conceptually the same idea, just done slightly more efficently
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class Test {
public static void main(String[] args) {
new Test();
}
public Test() {
EventQueue.invokeLater(new Runnable() {
#Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
ex.printStackTrace();
}
JFrame frame = new JFrame("Testing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new TestPane());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
public class TestPane extends JPanel {
private int recHeight = 0;
private int recWidth = 0;
//Here Buttons
JButton heightIncrease = new JButton("+");
JButton heightDecrease = new JButton("-");
JLabel height = new JLabel(Integer.toString(recHeight));
JLabel width = new JLabel(Integer.toString(recWidth));
GridLayout gridLayout = new GridLayout(2, 4);
public TestPane() {
setLayout(new BorderLayout());
//Create GridPanel and set Layout
JPanel grid = new JPanel();
grid.setLayout(gridLayout);
grid.add(height);
grid.add(width);
//Create buttondrawPanel and set Layout
JPanel buttondraw = new JPanel();
buttondraw.setLayout(new GridLayout(2, 0));
heightIncrease.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
recHeight += 1;
height.setText(Integer.toString(recHeight));
}
});
heightDecrease.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
recHeight -= 1;
height.setText(Integer.toString(recHeight));
}
});
buttondraw.add(heightIncrease);
buttondraw.add(heightDecrease);
//Adding Components to GridPanel
//Adding Layouts to pane
add(grid, BorderLayout.NORTH);
add(new JSeparator(), BorderLayout.CENTER);
add(buttondraw, BorderLayout.SOUTH);
}
}
}
I would encourage you to spend some time having a look at How to Use Buttons, Check Boxes, and Radio Buttons and How to Write an Action Listeners for more details

After changing the value call
frame.repaint();

Good to see you learning Java! A few things I should point out.
Firstly, your variable names are good, but they don't follow the Java naming convention. Even though it seems small, it's just good practice to follow.
Of course, your actual problem; the action listener you've implemented is on the JFrame. (See how you extend JFrame and implement ActionListener?) This ActionListener should be on the button. You'll can do this a few ways.
Method 1: By adding it inline with your code
JButton heightButton = new JButton("Increase Height");
heightButton.addActionListener(new ActionListener(){
#Override
public void run(){
//run method here
}
});
Method 2: Create a class which implements ActionListener
class ButtonListener implements ActionListener{
#Override
public void run(){
//actionListener code here
}
}
And then instantiate an object of this type and add it directly to your code.
ActionListner buttonListener = new ButtonListener(); //or ButtonListener buttonListener = new ButtonListener();
JButton heightButton = new JButton("Increase Height");
heightButton.addActionListener(buttonListener);
Of course, as in MadProgrammers answer, don't forget to add the labels and such to your JFrame or JPanel. Good luck learning Java!

I bet that your program just shows nothing, isn't it? That's because in addComponentsToPane method, you didn't add any component but empty JPanels. After the comment //Adding Components to GridPanel, you should:
buttondraw.add(HeightIncrease);
buttondraw.add(HeightDecrease);
grid.add(height);
grid.add(width);
Then, to listen to button event, you should also add :
HeightIncrease.addActionListener(this);
HeightDecrease.addActionListener(this);
"this" is because your frame JFrameSetUp implements ActionListener, so when either bootton is clicked the method actionPerformed is invoked.
As JLabel.setText method will repaint itself and consequently its component hierarchi is repainted as well, you haven't to do anything othr.

Related

How to fix JButton Location

Previously I have asked a question about this program and I fixed it with you people. Now I have created new panel on the first panel which is containing the game of shapes. So I tried to set JButton on the new panel. But I cannot change the location of Jbuttons.
I am trying to set center of new panel.I have tried already FLowLayout(), BorderLayout() and setBounds(); Something is going wrong.
Previous questions; How to move JFrame shape
public class myshapestry extends JFrame implements ActionListener {
JFrame frame=new JFrame("Deneme");
Startthegame panelstart= new Startthegame();
Container l ;
JLabel statusbar = new JLabel("default");
static JButton start;
static JButton exit;
myshapestry() {
l=this.getContentPane();
this.setLayout(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.add(panelstart);
frame.add(statusbar, BorderLayout.SOUTH);
frame.setVisible(true);
frame.setSize(getPreferredSize());
start = new JButton("Start");
exit = new JButton("Exit");
panelstart.add(start);
panelstart.add(exit);
}
public Dimension getPreferredSize() {
return new Dimension(500,600);
}
public static void main (String args[]){
myshapestry tr=new myshapestry();
tr.setTitle("Game of Shapes");
}
public class Startthegame extends JPanel {
}
}
You're extending from JFrame, but creating a new instance of JFrame within the class and interacting with both, which is just confusing the issues. Start by getting rid of extends JFrame, you're not adding any new functionality to the class and it's just locking you into a single use case
static is not your friend and you should avoid using it where possible. In this case, you can move the buttons to the Startthegame. This is basic OO principle of isolation responsibility to units of work.
To get the buttons to center horizontally and vertically within the container, you can use a GridBagLayout
public class Startthegame extends JPanel {
private JButton start;
private JButton exit;
public Startthegame() {
setLayout(new GridBagLayout());
start = new JButton("Start");
exit = new JButton("Exit");
add(start);
add(exit);
}
#Override
public Dimension getPreferredSize() {
return new Dimension(500, 600);
}
}
You should also call setVisible AFTER you've established the basic UI, otherwise you could end up within components not been displayed
For example...
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.GridBagLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class MyShapesTry {
JFrame frame = new JFrame("Deneme");
Startthegame panelstart = new Startthegame();
Container l;
JLabel statusbar = new JLabel("default");
public MyShapesTry() {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(panelstart);
frame.add(statusbar, BorderLayout.SOUTH);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String args[]) {
EventQueue.invokeLater(new Runnable() {
#Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
ex.printStackTrace();
}
MyShapesTry tr = new MyShapesTry();
}
});
}
}

JButton Wont Display JPanel

I want to call My JPanel with button. My Jpanel is actually a sub JPanel from main Panel with card layout.
to do that, i am using card layout api method HERE to show the JPanel after a button was clicked.
JButton btnCallPanel1 = new JButton("Call PanelOne");
btnCallPanel1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
CardLayout card = (CardLayout)mainPanel.getLayout();
card.show(mainPanel, "PanelOne"); //call Panel One
}
output :
nothing appear, panel not called and no error pop out.
My Code is HERE
package wan.dev.sample.cardlayout;
import java.awt.CardLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JLabel;
public class HowToUseCardLayout {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
HowToUseCardLayout window = new HowToUseCardLayout();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public HowToUseCardLayout() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 688, 358);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JPanel mainPanel = new JPanel();
mainPanel.setBounds(0, 0, 672, 260);
frame.getContentPane().add(mainPanel);
mainPanel.setLayout(new CardLayout(0, 0));
JPanel PrePanel = new JPanel();
mainPanel.add(PrePanel, "name_246268073832057");
PrePanel.setLayout(null);
JLabel lblPanel_1 = new JLabel("Pre Panel");
lblPanel_1.setBounds(280, 115, 57, 20);
PrePanel.add(lblPanel_1);
JPanel panelOne = new JPanel();
mainPanel.add(panelOne, "name_246268067657434");
panelOne.setLayout(null);
JLabel lblPanel = new JLabel("panel 1");
lblPanel.setBounds(279, 118, 46, 14);
panelOne.add(lblPanel);
JButton btnPan1 = new JButton("Call PanelOne");
btnPan1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
CardLayout card = (CardLayout) mainPanel.getLayout();
card.show(mainPanel, "PanelOne");
}
});
btnPan1.setBounds(262, 286, 144, 23);
frame.getContentPane().add(btnPan1);
}
}
ANSWER
The reason i cant call my panel because i did not call it by using identifier.
i have to give identifier name to my desire jpanel and use the identifier on my cardLayout.show(..)
Public Static final String PANEL_ONE = "panel one"; //Name of JPanel Identifier
//add panel to main panel and declare panelOne identifier
mainPanel.add(panelOne, PANEL_ONE); //PANEL_ONE function like
//an identifier
JButton btnCallPanel1 = new JButton("Call PanelOne");
btnCallPanel1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
CardLayout card =
(CardLayout)mainPanel.getLayout();
card.show(mainPanel, PANEL_ONE); //call panelOne using PANEL_ONE
//instead of JPanel name
}
As I suspected — You're calling the CardLayout.show(...) method with the String parameter "PanelOne", but yet you've not added any component to the CardLayout-using container using this same String, so it makes sense that it won't work. Solution: don't do this. Use the Same String that you add the component to the CardLayout using container as the one that you use to display it.
i.e., If you want to display container foo and use the String "bar" to add it to the CardLayout-using container, then you must pass "bar" into the CardLayout's show(...) method. Again, use String constants for this so that you reduce the chances of messing up.
Other issues: You're using null layout and setBounds — Don't. Doing this makes for very inflexible GUI's that while they might look good on one platform look terrible on most other platforms or screen resolutions and that are very difficult to update and maintain.
e.g.,
import java.awt.CardLayout;
import java.awt.event.ActionEvent;
import javax.swing.*;
public class CardLayoutFoo extends JPanel {
public static final String BAR = "bar";
public static final String BUTTON_PANEL = "button panel";
private CardLayout cardlayout = new CardLayout();
public CardLayoutFoo() {
setLayout(cardlayout);
JLabel fooLabel = new JLabel("Foo", SwingConstants.CENTER);
add(fooLabel, BAR); // added using String constant, BAR
JButton showFooBtn = new JButton(new AbstractAction("Show Foo") {
#Override
public void actionPerformed(ActionEvent evt) {
// use same String, BAR, to get the fooLabl shown
cardlayout.show(CardLayoutFoo.this, BAR);
}
});
JPanel btnPanel = new JPanel();
btnPanel.add(showFooBtn);
add(btnPanel, BUTTON_PANEL);
cardlayout.show(this, BUTTON_PANEL);
}
private static void createAndShowGui() {
CardLayoutFoo mainPanel = new CardLayoutFoo();
JFrame frame = new JFrame("CardLayoutFoo");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.getContentPane().add(mainPanel);
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGui();
}
});
}
}

How would I use a button in Java to open Jframe over existing Jframe

I have 2 frames, the first frame has the nothing more and a button, which leads to another frame which will have all the components, like tabs which have more components.
The code I am using is:
button_1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e) {
JFrame Frame_2 = new JFrame();
Frame_1.setVisible(false);
Frame_2.setVisible(true);
}
});
this is creating a new separate frame , but i want to create new JFrame over existing JFrame
update
#VinceEmigh +1
Thanks for the detail custom solution. It shows that someone is really willing to help, I am a self learner , started just 3 months ago so your code is bit difficult to understand, but the idea of using cardlayout did the work and i came up with a solution.
JFrame guiFrame = new JFrame();
CardLayout cards;
JPanel cardPane;
JButton B_1 = new JButton("Next Card");
B_1.setActionCommand("Next Card");
B_1.addActionListener(new ActionListener()
{
#Override
public void actionPerformed(ActionEvent event)
{
cards.next(cardPane);
}
});
cards = new CardLayout();
cardPane = new JPanel();
cardPane.setLayout(cards);
cards.show(cardPane, "Main");
JPanel Card_1 = new JPanel();
JLabel background_1 = new JLabel(new ImageIcon("C:\\Users\\ME\\Desktop\\Back1.jpg"));
Card_1.add(background_1);
Card_1.add(B_1);
JPanel Card_2 = new JPanel();
JLabel background_2 = new JLabel(new ImageIcon("C:\\Users\\ME\\Desktop\\Back2.jpg"));
Card_2.add(background_2);
cardPane.add(Card_1, "Main");
cardPane.add(Card_2, "Sub");
You shouldnt use 2 frames. You should use 1 frame, then switch between panels in the frame using CardLayout. Unless you're referring to nesting a frame within a frame, creating 2 different frames for 1 applicarion is typically bad practice, and should be avoided if possible.
Set your frames layout to CardLayout, add 2 panels to your frame. One panel contains the button, the other has the components.
When your button event triggers throuhh an actionlistener, switch out the panels using the cardlayout you put for the frames layout.
import java.awt.CardLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class App extends JFrame {
private CardLayout cl = new CardLayout();
private JPanel firstPanel = new FirstPanel();
private JPanel secondPanel = new SecondPanel();
public App() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(500, 500);
setLayout(cl);
add(firstPanel, "first");
add(secondPanel, "second");
setLocationRelativeTo(null);
setVisible(true);
}
public void switchPanel(String name) {
cl.show(getContentPane(), name);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
App app = new App();
}
});
}
class FirstPanel extends JPanel implements ActionListener {
private JButton button = new JButton("Button");
public FirstPanel() {
button.addActionListener(this);
add(button);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == button) {
switchPanel("second");
}
}
}
class SecondPanel extends JPanel { }
}

Adding jinternalframe class to jdesktoppane using other jinternalframe class

I'm creating a very simple program.
I have created this classes :
MainJframeClass, JDesktopPaneClass, JinternalFrameClass1 and JinternalFrameClass2.
what ive done is that i instantiated my jdesktoppaneclass and named it desktoppane1 and i added it to the MainJframeclass. i have also instantiated the 2 jinternalframes and named it internal1 and internal2. Now, i have button in mainjframeclass that when i press, i add the internal1 to desktoppane1. what my problem now is how to add the internal2 to desktoppane1 using a button placed somewhere in internal1. i know that why could i just add another button to desktoppane1 and add the internal2. but i have done it already, i just want to solve this problem. if you can help me please. sorry for my english by the way.
It's simply a matter of references. The code that adds something to the JDesktopPane must have a reference to it, and so you will need to pass that reference into the class that needs it say via either a constructor parameter or a method parameter.
Edit 1
For example:
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
import javax.swing.*;
public class ReferenceExample extends JPanel {
private JDesktopPane desktop = new JDesktopPane();
private Random random = new Random();
public ReferenceExample() {
JButton addInternalFrameBtn = new JButton("Add Internal Frame");
addInternalFrameBtn.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
addInternalFrame();
}
});
JPanel btnPanel = new JPanel();
btnPanel.add(addInternalFrameBtn);
setPreferredSize(new Dimension(600, 450));
setLayout(new BorderLayout());
add(new JScrollPane(desktop), BorderLayout.CENTER);
add(btnPanel, BorderLayout.SOUTH);
}
public void addInternalFrame() {
MyInternalFrame intFrame = new MyInternalFrame(ReferenceExample.this);
int x = random.nextInt(getWidth() - intFrame.getPreferredSize().width);
int y = random.nextInt(getHeight() - intFrame.getPreferredSize().height);
intFrame.setLocation(x, y);
desktop.add(intFrame);
intFrame.setVisible(true);
}
private static void createAndShowUI() {
JFrame frame = new JFrame("Reference Eg");
frame.getContentPane().add(new ReferenceExample());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
createAndShowUI();
}
});
}
}
class MyInternalFrame extends JInternalFrame {
// pass in the reference in the constructor
public MyInternalFrame(final ReferenceExample refEg) {
setPreferredSize(new Dimension(200, 200));
setClosable(true);
JButton addInternalFrameBtn = new JButton("Add Internal Frame");
addInternalFrameBtn.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
// use the reference here
refEg.addInternalFrame();
}
});
JPanel panel = new JPanel();
panel.add(addInternalFrameBtn);
getContentPane().add(panel);
pack();
}
}
how to add the internal2 to desktoppane1 using a button placed somewhere in internal1.
In the ActionListener added to your button you can use code like the following to get a reference to the desktop pane:
Container container = SwingUtilities.getAncestorOfClass(JDesktopPane.class, (Component)event.getSource());
if (container != null)
{
JDesktopPane desktop = (JDesktopPane)container;
JInternalFrame frame = new JInternalFrame(...);
desktop.add( frame );
}

why are my buttons not showing up?

I am trying to create an array of buttons as a simulation of a seatingChart, but the buttons wont show up on the screen only the frame shows up. what am I doing wrong?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class guiCreator extends JFrame
{
public guiCreator()
{
setTitle("Seats");
setSize(500, 600);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0);
}
} );
Container contentPane = getContentPane();
contentPane.add(new seatingPanel());
setVisible(true);
}
}
class seatingPanel extends JPanel implements ActionListener
{
public seatingPanel()
{
setLayout(new BorderLayout());
JPanel panel4seating = new JPanel();//creating a grid panel
panel4seating.setLayout(new GridLayout(4, 10));//setting the layout of the grid panel
JButton [] seats = new JButton [40]; //creating a pointer to the buttonsArray
for (int i = 0; i < 40; i++)
{
seats[i] = new JButton();//creating the buttons
seats[i].addActionListener(this);
panel4seating.add(seats[i]);
}
}
#Override
public void actionPerformed(ActionEvent evt)
{
}
//main
guiCreator flightSeats = new guiCreator();
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class GuiCreator extends JFrame
{
public GuiCreator()
{
super("Seats");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container contentPane = getContentPane();
contentPane.add(new SeatingPanel());
pack();
setVisible(true);
}
public static void main(String[] args) {
new GuiCreator();
}
}
class SeatingPanel extends JPanel
{
public SeatingPanel()
{
super(new BorderLayout());
JPanel panel4seating = new JPanel();//creating a grid panel
panel4seating.setLayout(new GridLayout(4, 10));//setting the layout of the grid panel
JButton [] seats = new JButton [40]; //creating a pointer to the buttonsArray
for (int i = 0; i < 40; i++)
{
seats[i] = new JButton();//creating the buttons
//better to set the preferred size of the button
seats[i].setPreferredSize(new Dimension(50,25));
panel4seating.add(seats[i]);
}
add(panel4seating, BorderLayout.CENTER);
}
}
GUIs should be created on the EDT (my laziness).
Use camel case for names.
It is not necessary to extend either JFrame or JPanel in this instance.
The other (undocumented) changes to the source are improvements. If you have questions on any part of the changes, ask.
You're creating a new JPanel in seatingPanel's constructor, but you're not adding it to the seatingPanel itself, so it won't show up at all.
Try adding it to the seatingPanel's layout.
(Or do away with that sub-panel entirely - set the grid layout and and the buttons directly to your seatingPanel.)

Categories