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 3983782
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:41:26+00:00 2026-05-20T05:41:26+00:00

I am attempting to make a program for a local bagel shop that sells

  • 0

I am attempting to make a program for a local bagel shop that sells pastries, bagels, and coffee. I am having trouble implementing the panels that I have made into the JFrame

any help understanding how to make my JFrame look like this would be helpful http://kepler.covenant.edu/COS150/Bagel_files/image002.jpg

Once I have this working I hope to have the middle set of panels change depending on which product is selected. I am not entirely sure how to make the buttons and panels talk to one another.

Thanks for the Help!

here is my code for the JFrame so far.

import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class BagelOrder extends JFrame
{   
JLabel topLabel;

sizePanel sp = new sizePanel();
typePanel tp = new typePanel();
productsPanel pp = new productsPanel();
buttonPanel bp = new buttonPanel();
extrasPanel ep = new extrasPanel();

public BagelOrder()
{
    setTitle("Order Entry Screen");
    setSize(800, 800);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    topLabel = new JLabel("Order Entry Screen");
    add(pp, BorderLayout.WEST);
    add(topLabel, BorderLayout.NORTH);
    add(bp, BorderLayout.SOUTH);
    add(middleCoffeePanelSetBuild(), BorderLayout.CENTER);
    add(east, BorderLayout.EAST);
    setVisible(true);

}

private JPanel middleCoffeePanelSetBuild()
{
    JPanel middlePanel = new JPanel(new GridLayout(3,1));
    add(sp);
    add(tp);
    add(ep);

    }

public static void main(String args[])
{
    BagelOrder bo = new BagelOrder();
}



} 

I have no errors but I cannot see anything other than the label at the top of the page.

here is my code for the other classes

ButtonPanel

import java.awt.GridLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JPanel;


public class buttonPanel extends JPanel
{
JButton enterItemButton;
JPanel buttonPanel;
ButtonGroup bg;
JButton totalButton;
JButton newOrderButton;


public buttonPanel()
{
    buttonPanel = new JPanel(new GridLayout(1,3));
    bg = new ButtonGroup();
    enterItemButton = new JButton("Enter Item");
    totalButton = new JButton("Total");
    newOrderButton = new JButton("New Order");

    buttonPanel.setSize(150, 780);
    buttonPanel.add(enterItemButton);
    bg.add(enterItemButton);
    buttonPanel.add(totalButton);
    bg.add(totalButton);
    buttonPanel.add(newOrderButton);
    bg.add(newOrderButton);
    setVisible(true);   

}
}

ProductPanel

import java.awt.GridLayout;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.border.Border;


public class productsPanel extends JPanel
{
public productsPanel()
{
    JPanel productPanel = new JPanel(new GridLayout(3,1));
    ButtonGroup bg = new ButtonGroup();
    JRadioButton coffeeButton = new JRadioButton("Coffee");
    JRadioButton bagelButton = new JRadioButton("Bagel");
    JRadioButton pastryButton = new JRadioButton("Pastry");

    productPanel.setSize(150, 780);
    productPanel.add(coffeeButton);
    bg.add(coffeeButton);
    productPanel.add(bagelButton);
    bg.add(bagelButton);
    productPanel.add(pastryButton);
    bg.add(pastryButton);

    Border etched = BorderFactory.createEtchedBorder();
    Border titled = BorderFactory.createTitledBorder(etched, "Products");
    productPanel.setBorder(titled);
    setVisible(true);   
}
}

Size Panel

import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.border.Border;


public class sizePanel extends JPanel{

public sizePanel()
{
    JPanel sp = new JPanel(new GridLayout(3,1));
    ButtonGroup bg = new ButtonGroup();
    JRadioButton smallButton = new JRadioButton("Small");
    JRadioButton mediumButton = new JRadioButton("Medium");
    JRadioButton largeButton = new JRadioButton("Large");

    sp.setSize(200, 200);
    sp.add(smallButton);
    bg.add(smallButton);
    sp.add(mediumButton);
    bg.add(mediumButton);
    sp.add(largeButton);
    bg.add(largeButton);


    Border etched = BorderFactory.createEtchedBorder();
    Border titled = BorderFactory.createTitledBorder(etched, "Size");   
    sp.setBorder(titled);
    setVisible(true);   
}
}

TypePanel

import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.border.Border;


public class typePanel extends JPanel
{
public typePanel()
{
    JPanel typePanel = new JPanel(new GridLayout(3,1));
    ButtonGroup bg = new ButtonGroup();
    JRadioButton regularButton = new JRadioButton("Regular");
    JRadioButton decafButton = new JRadioButton("Decaf");
    JRadioButton frenchRoastButton = new JRadioButton("French Roast");

    typePanel.setSize(200, 200);
    typePanel.add(regularButton);
    bg.add(regularButton);
    typePanel.add(decafButton);
    bg.add(decafButton);
    typePanel.add(frenchRoastButton);
    bg.add(frenchRoastButton);


    Border etched = BorderFactory.createEtchedBorder();
    Border titled = BorderFactory.createTitledBorder(etched, "Type");   
    typePanel.setBorder(titled);
    setVisible(true);   
}
}

ExtrasPanel

 import java.awt.GridLayout;
 import javax.swing.BorderFactory;
 import javax.swing.JCheckBox;
 import javax.swing.JPanel;
 import javax.swing.border.Border;


public class extrasPanel extends JPanel
{
public extrasPanel()
{
    JPanel extrasPanel = new JPanel(new GridLayout(2,1));

    JCheckBox creamCheckBox = new JCheckBox("Cream");
    JCheckBox sugarCheckBox = new JCheckBox("Sugar");   

    extrasPanel.setSize(200, 200);
    extrasPanel.add(creamCheckBox);
    extrasPanel.add(sugarCheckBox);

    Border etched = BorderFactory.createEtchedBorder();
    Border titled = BorderFactory.createTitledBorder(etched, "Extras");
    extrasPanel.setBorder(titled);
    setVisible(true);
}
}
  • 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-05-20T05:41:26+00:00Added an answer on May 20, 2026 at 5:41 am

    Some good practices to get into when writing Swing GUI’s:

    1) Your Panel classes are built wrong.
    You need to re-write buttonPanel, and all of your others, so that they read like this:

    public buttonPanel() {
        super(new GridLayout(1,3));
        bg = new ButtonGroup();
        enterItemButton = new JButton("Enter Item");
        totalButton = new JButton("Total");
        newOrderButton = new JButton("New Order");
    
        this.setSize(150, 780);
        this.add(enterItemButton);
        bg.add(enterItemButton);
        this.add(totalButton);
        bg.add(totalButton);
        this.add(newOrderButton);
        bg.add(newOrderButton);
        this.setVisible(true);
    
        }
    }
    

    The way yours is currently written, you have a ButtonPanel class (always capitalise classes) which posseses a JPanel with the buttons on it, but it never displays this JPanel that it owns. You need ButtonPanel to BE a JPanel, not just own one.
    Thats the major issue. Minor points you could improve on:

    2) The JFrame has a JPanel called the contentPane. As said by jzd, when using JFrame.add you are really calling JFrame.getContentPane.add(Component c). This is a convenience method, but it hides what you are really doing. Especially when you’re just learning, shortcuts are bad.

    I personally go a step further, starting my JFrames off with

    JPanel content = new JPanel(new BorderLayout());
    content.add(...);
    ....
    this.setContentPane(content);
    

    3) It is good practice when extending a class (like JFrame) to begin with a call to super(). Again, you can leave it out as shorthand, but its good to be pedantic when beginning. This calls the superclass’s constructor (with whatever arguments you need), which is basically saying “Lets create the basic JFrame, and then apply my extensions to it”.

    4) Its also good practice to capitalise your classes, and begin all functions with lowercase verbs. ie ButtonPanel or build()

    5) It seems like you’re only just starting out with GUI, but might I recommend the external library “MigLayout” (google it). Its amazing in the extra power and ease that it gives you over struggling against all of Java’s inbuilt, horrible, layout types.

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

Sidebar

Related Questions

I am attempting to make a program that will pull data such as OS,
I am attempting to make a program in C which presents a GUI and
I'm currently attempting to implement having a (signed) applet communicate to a server program
I'm attempting to make a classifier that chooses a rating (1-5) for a item
I am attempting to make a simple class that serializes itself to disk when
Attempting to print out a list of values from 2 different variables that are
I am attempting to install libxml2 so that I can setup the python bindings
I'm wondering what is the recommended audio library to use? I'm attempting to make
I am attempting to make an application capable of running on both Sql Server
I am attempting to create a basic Hangman program. It's an array of tags

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.