This site requires JavaScript, please enable it in your browser!
Greenfoot back
divinity
divinity wrote ...

2017/5/17

been trying to get this pizza main gui program to work

divinity divinity

2017/5/17

#
hi I am doing an assignment for object oriented programming and i have only a few day to hand up this assignment. have been having some issues coding it and the codes that I hve dont kno if it is the correct one. can someone tell me if I am on the right track or am way off . the code below is what i have so for. the place order JButton is not functioning and how do i get it to function and so is the your order details JButton is not functioning. plz
import java.awt.Container;
import java.awt.GridLayout;
import java.util.ArrayList;
import java.util.List;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.ButtonGroup;



public  class PizzaMania extends JFrame {

    static ArrayList <Pizza > pizza = new ArrayList <Pizza>();
    private ButtonModel ThinCrust;
    
public PizzaMania (){
   
         setSize(250,250);
         setLocationRelativeTo(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
          
        initComponents();
}
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        pizzaSize = new javax.swing.ButtonGroup();
        pizzaType = new javax.swing.ButtonGroup();
        Toppings = new javax.swing.ButtonGroup();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        tomatoes = new javax.swing.JCheckBox();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        greenbellpeppers = new javax.swing.JCheckBox();
        jRadioButton3 = new javax.swing.JRadioButton();
        jRadioButton4 = new javax.swing.JRadioButton();
        blackolives = new javax.swing.JCheckBox();
        jRadioButton5 = new javax.swing.JRadioButton();
        jRadioButton6 = new javax.swing.JRadioButton();
        mushrooms = new javax.swing.JCheckBox();
        jRadioButton7 = new javax.swing.JRadioButton();
        extracheese = new javax.swing.JCheckBox();
        pepperoni = new javax.swing.JCheckBox();
        sausage = new javax.swing.JCheckBox();
        jCheckBox8 = new javax.swing.JCheckBox();
        plceorder = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jButton2 = new javax.swing.JButton();
        detailsbtn3 = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        ClearFormBnMenuItem1 = new javax.swing.JRadioButtonMenuItem();
        ExitBnMenuItem2 = new javax.swing.JRadioButtonMenuItem();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(204, 0, 0));
        setIconImages(null);

        jLabel2.setForeground(new java.awt.Color(0, 102, 0));
        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pizza-mania (1).jpg"))); // NOI18N

        jLabel1.setFont(new java.awt.Font("Cambria", 1, 14)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(153, 0, 0));
        jLabel1.setText("            Welcome to PizzaMania");

        jLabel3.setFont(new java.awt.Font("Cambria", 3, 14)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(0, 153, 51));
        jLabel3.setText("Each Topping: $1.50");

        jLabel5.setFont(new java.awt.Font("Cambria", 3, 14)); // NOI18N
        jLabel5.setForeground(new java.awt.Color(0, 204, 0));
        jLabel5.setText("Pizza Type");

        jLabel4.setFont(new java.awt.Font("Cambria", 3, 14)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(0, 153, 0));
        jLabel4.setText("Pizza Size");

        Toppings.add(tomatoes);
        tomatoes.setFont(new java.awt.Font("Cambria", 3, 12)); // NOI18N
        tomatoes.setText("Tomato");

        pizzaSize.add(jRadioButton1);
        jRadioButton1.setFont(new java.awt.Font("Cambria", 3, 12)); // NOI18N
        jRadioButton1.setText("Small: $25.00");

        pizzaType.add(jRadioButton2);
        jRadioButton2.setFont(new java.awt.Font("Cambria", 3, 12)); // NOI18N
        jRadioButton2.setText("Thin Crust");

        Toppings.add(greenbellpeppers);
        greenbellpeppers.setFont(new java.awt.Font("Cambria", 3, 12)); // NOI18N
        greenbellpeppers.setText("GreenBell Pepper");

        pizzaSize.add(jRadioButton3);
        jRadioButton3.setFont(new java.awt.Font("Cambria", 3, 12)); // NOI18N
        jRadioButton3.setText("Medium: $50.00");

        pizzaType.add(jRadioButton4);
        jRadioButton4.setFont(new java.awt.Font("Cambria", 3, 12)); // NOI18N
        jRadioButton4.setText("Medium Crust");

        Toppings.add(blackolives);
        blackolives.setFont(new java.awt.Font("Cambria", 3, 12)); // NOI18N
        blackolives.setText("Black Olives");

        pizzaSize.add(jRadioButton5);
        jRadioButton5.setFont(new java.awt.Font("Cambria", 3, 12)); // NOI18N
        jRadioButton5.setText("Large: $75.00");

        pizzaType.add(jRadioButton6);
        jRadioButton6.setFont(new java.awt.Font("Cambria", 3, 12)); // NOI18N
        jRadioButton6.setText("Crust lover");

        Toppings.add(mushrooms);
        mushrooms.setFont(new java.awt.Font("Cambria", 3, 12)); // NOI18N
        mushrooms.setText("Mushrooms");

        pizzaSize.add(jRadioButton7);
        jRadioButton7.setFont(new java.awt.Font("Cambria", 3, 12)); // NOI18N
        jRadioButton7.setText("Family: $130.00");

        Toppings.add(extracheese);
        extracheese.setFont(new java.awt.Font("Cambria", 3, 12)); // NOI18N
        extracheese.setText("Extra Cheese");

        Toppings.add(pepperoni);
        pepperoni.setFont(new java.awt.Font("Cambria", 3, 12)); // NOI18N
        pepperoni.setText("Pepperoni");

        Toppings.add(sausage);
        sausage.setFont(new java.awt.Font("Cambria", 3, 12)); // NOI18N
        sausage.setText("Sausage");

        jCheckBox8.setFont(new java.awt.Font("Cambria", 3, 12)); // NOI18N
        jCheckBox8.setText("Members Card");

        plceorder.setFont(new java.awt.Font("Cambria", 3, 12)); // NOI18N
        plceorder.setForeground(new java.awt.Color(153, 0, 0));
        plceorder.setText("Place Order");
        plceorder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                plceorderActionPerformed(evt);
            }
        });

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        jButton2.setFont(new java.awt.Font("Cambria", 3, 12)); // NOI18N
        jButton2.setForeground(new java.awt.Color(153, 0, 0));
        jButton2.setText("Print All Orders");

        detailsbtn3.setFont(new java.awt.Font("Cambria", 3, 12)); // NOI18N
        detailsbtn3.setForeground(new java.awt.Color(153, 0, 0));
        detailsbtn3.setText("Your Order Details");
        detailsbtn3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                detailsbtn3ActionPerformed(evt);
            }
        });

        jMenu1.setText("File");

        ClearFormBnMenuItem1.setFont(new java.awt.Font("Cambria", 1, 12)); // NOI18N
        ClearFormBnMenuItem1.setSelected(true);
        ClearFormBnMenuItem1.setText("Clear Form");
        ClearFormBnMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ClearFormBnMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(ClearFormBnMenuItem1);

        ExitBnMenuItem2.setFont(new java.awt.Font("Cambria", 1, 12)); // NOI18N
        ExitBnMenuItem2.setSelected(true);
        ExitBnMenuItem2.setText("Exit");
        ExitBnMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ExitBnMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(ExitBnMenuItem2);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(28, 28, 28)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(0, 0, Short.MAX_VALUE)
                                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(91, 91, 91)
                                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(113, 113, 113))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                .addComponent(tomatoes, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(greenbellpeppers, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                            .addComponent(blackolives))
                                        .addGap(104, 104, 104)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jRadioButton3)
                                            .addComponent(jRadioButton1)
                                            .addComponent(jRadioButton5)
                                            .addComponent(jRadioButton7)
                                            .addComponent(jCheckBox8)
                                            .addComponent(plceorder, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jRadioButton2)
                                    .addComponent(jLabel5)
                                    .addComponent(jRadioButton4)
                                    .addComponent(jRadioButton6))
                                .addGap(48, 48, 48))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(mushrooms, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(pepperoni, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(extracheese, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(sausage, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(detailsbtn3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(0, 0, Short.MAX_VALUE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(33, 33, 33))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(203, 203, 203)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(156, 156, 156)
                        .addComponent(jLabel2)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel1)
                .addGap(45, 45, 45)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5))
                .addGap(33, 33, 33)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tomatoes)
                            .addComponent(jRadioButton2))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(greenbellpeppers)
                            .addComponent(jRadioButton4))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(blackolives)
                            .addComponent(jRadioButton6))
                        .addGap(18, 18, 18)
                        .addComponent(mushrooms)
                        .addGap(18, 18, 18)
                        .addComponent(extracheese)
                        .addGap(18, 18, 18))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jRadioButton1)
                        .addGap(18, 18, 18)
                        .addComponent(jRadioButton3)
                        .addGap(18, 18, 18)
                        .addComponent(jRadioButton5)
                        .addGap(18, 18, 18)
                        .addComponent(jRadioButton7)
                        .addGap(18, 18, 18)
                        .addComponent(jCheckBox8)
                        .addGap(27, 27, 27)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(pepperoni)
                    .addComponent(plceorder, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(sausage)
                .addGap(18, 18, 18)
                .addComponent(detailsbtn3, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>                        
    public void initComponent(){
        
        JCheckBox tomatoes = new javax.swing.JCheckBox();
        JCheckBox greenbellpeppers = new javax.swing.JCheckBox();
        JCheckBox blackolives = new javax.swing.JCheckBox();
        JCheckBox mushrooms = new javax.swing.JCheckBox();
        JCheckBox extracheese = new javax.swing.JCheckBox();
        JCheckBox pepperoni = new javax.swing.JCheckBox();
        JCheckBox sausage = new javax.swing.JCheckBox();
        
        JCheckBox membercard = new javax.swing.JCheckBox();
        membercard.add(this);
        
        JButton plceorder = new javax.swing.JButton();
        plceorder.add(this);
        
        JButton details = new javax.swing.JButton();
        details.add(this);
        
        
        
        JRadioButton small = new javax.swing.JRadioButton();
        JRadioButton medium = new javax.swing.JRadioButton();
        JRadioButton large = new javax.swing.JRadioButton();
        JRadioButton family= new javax.swing.JRadioButton();
        
        ButtonGroup bgroup = new ButtonGroup();
        bgroup.add(large);
        bgroup.add(small);
        bgroup.add(medium);
        bgroup.add(family);
        
        bgroup.setSelected(bgroup.getSelection(), true);
        
        JButton thincrust = new javax.swing.JButton();
        JButton mediumcrust = new javax.swing.JButton();
        JButton crustlover = new javax.swing.JButton();
        
        ButtonGroup bg = new ButtonGroup();
        bg.add(thincrust);
        bg.add(mediumcrust);
        bg.add(crustlover);
            
    }
 
    
  
    
    private void ClearFormBnMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                                     
       ClearFormBnMenuItem1.setText("");       
    }                                                    

    private void ExitBnMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {                                                
       System.exit(0);
       
    }                                               

    private void plceorderActionPerformed(java.awt.event.ActionEvent evt) {                                          
        plceorder.setText("place order");
        
        
       if(pizzaSize.isSelected(ThinCrust)){
            double costofTopping = 1.50;
            
            System.out.println(plceorder.getText()+"Place your order ");
       }
       
       
        
        
        
    }                                         

    private void detailsbtn3ActionPerformed(java.awt.event.ActionEvent evt) {                                            
        detailsbtn3.setText("your order details");
Yehuda Yehuda

2017/5/18

#
I don't know what the plceorder JButton is supposed to do. Right now it will change it's text to "place order" and if pizzaSize.isSelected(ThinCrust) then it will also display in the terminal window "place orderPlace your order ". I know this from lines 375 - 383. What is the plceorder button supposed to do as opposed to what it does. (There are a lot of variables here that I don't know where they're created, also there is no main method.) (P. S. It looks like you created the JFrame with the NetBeans IDE GUI builder or something like that.)
You need to login to post a reply.