import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class PizzaOrder {
public static void main(String[] args) {
OrderFrame frame = new OrderFrame();
}
}
class OrderFrame extends JFrame {
public OrderFrame() {
applySettings();
addComponents();
setListeners();
...
}
private void applySettings() {
...
}
private void addComponents() {
...
}
private void setListeners() {
...
}
private void updateOrder() {
...
}
// Declare Components
...
private double totalCost = 0;
private String orderString = "";
private String[] size = new String[] {"Small ($8.50)", "Medium ($10.50)", "Large ($12.50)"};
private String[] toppings = new String[] {"onions ($1.25)", "black olives ($1.50)", "pineapple ($2.00)", "mushroom ($2.25)"};
}
Description and Objective
- This app calculates the price of a pizza based on its size and toppings as seen in the figure above. The price and the order info should be displayed immediately after any modification.
Things to Do
- Use the above code as a template.
- Changing settings:
- Set the window title
- Set the background color
- Set the layout to BorderLayout
- Adding Components:
- Create a JPanel to contain labels and components for size selection. The panel should look like the top portion of the figure.
- Create a JPanel to contain labels and components for topping selection. The panel should look like the top portion of the figure.
- Create a JPanel to contain labels and components for order info. The panel should look like the top portion of the figure.
- Adding Listeners:
- When checked all radio buttons and checkboxes should behave the same, therefore you can instantiate a single listener object that would call the updateOrder function and change the values on the order info portion of the frame.
- Once instantiated you can add this as the listener to each component.
- updateOrder function should update the totalCost and orderString values based on the selections. The totalCost is tha cost of the pizza and the orderString is a shorthand description of the order (see bottom portion of the figure.