LAB ACTIVITY 2D
SWING COMPONENTS WITH LAYOUTS
SWING COMPONENTS WITH LAYOUTS
Learning Outcomes
By the end of this lab, students should be able to :
Write a Java program using Frame class from Swing package.
Write a Java Program using GUI objects from Swing package.
Hardware/ Software : Personal Computer, Java Development Kit version X.x.x., NetBeans IDE 12.0
LAB ACTIVITY 2D
Question:
Create the interface below:
1. Setup the Development Environment
Open your preferred Java IDE (e.g., NetBeans, IntelliJ IDEA, or Eclipse).
Create a new Java project.
Create a new Java class file, and name it LabAct3c.
2. Import Required Libraries
At the beginning of your Java file, import the necessary libraries to use Swing and other Java components.
3. Create the Main Class
Define the class LabAct3c that extends JFrame. This class will hold the main GUI components
4. Set Up GUI Components for Main Frame
In the constructor of LabAct3c, set up the basic properties of the frame:
Define the close operation using setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);.
Use setLayout(new FlowLayout()); to set a layout for the main container.
Add panels for different sections like the title, order form, and total section.
Define the frame size and make it visible using setVisible(true);.
5. Create the Title Panel
Create an inner class PanelTitle that extends JPanel.
Set the layout for this panel (use FlowLayout for simple horizontal placement).
Add a JLabel to display the title "BURGER ORDERING SYSTEM" in bold and larger font size
6. Create the Order Form Panel
Create another inner class OrderForm that extends JPanel.
Use GridBagLayout for a more structured layout, as this allows for easy alignment of labels, text fields, checkboxes, and combo boxes.
Add components for:
Order Number: Label and Text Field.
Product Selection: Checkboxes for different burger types (Beef, Chicken, Combo).
Quantity: Text fields to input quantities for each burger type.
Additional Options: Combo boxes for additional toppings like "Cheddar Cheese" and "Parmesan Cheese."
Order Type: Radio buttons for selecting delivery or self-pickup.
Other Costs: A slider to indicate additional costs.
7. Create the Total Panel
Define another inner class PanelTotal that extends JPanel.
Set up a grid layout for this panel and add components for the total payment calculation.
Add a text field that will eventually display the total price, but keep it disabled as it's only for display.
8. Compile and Run the Program
After setting up the layout and components in each of the inner panels (PanelTitle, OrderForm, and PanelTotal), compile and run the program.
This should display the GUI with all the components properly arranged.
9. Test the Interface
Run the program and interact with the GUI.
Although no functionality (event handling) is included, you should be able to see all the fields, buttons, checkboxes, radio buttons, combo boxes, and sliders.