Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· OpenAIAi2 WildChat-4.8M (AI2)

Fix the errors in my java code: import java.awt.EventQueue; import javax.swing.JFrame;…

  1. User

    Fix the errors in my java code: import java.awt.EventQueue;

    import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.JLabel; import java.awt.Font; import javax.swing.SwingConstants; import javax.swing.border.TitledBorder; import javax.swing.border.EtchedBorder; import java.awt.Color; import javax.swing.border.BevelBorder; import javax.swing.border.CompoundBorder; import javax.swing.border.LineBorder; import javax.swing.UIManager; import javax.swing.border.SoftBevelBorder; import javax.swing.border.MatteBorder; import java.awt.GridLayout; import javax.swing.ImageIcon; import javax.swing.JComboBox; import javax.swing.DefaultComboBoxModel; import javax.swing.BoxLayout; import java.awt.FlowLayout; import javax.swing.JTextField; import javax.swing.JButton; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.List; import java.awt.event.ActionEvent;

    public class PizzaOrder extends JFrame {

    private JPanel contentPane;
    private JPanel ToppingSelect;
    private JTextField NumPizza;
    private JTextField NumTopping;
    private JTextField NumBreuvage;
    private JButton Ajouter;
    private List<Double> orderList = new ArrayList<Double>();
    
    
    public static void main(String[] args) {
    	EventQueue.invokeLater(new Runnable() {
    		public void run() {
    			try {
    				PizzaOrder frame = new PizzaOrder();
    				frame.setVisible(true);
    			} catch (Exception e) {
    				e.printStackTrace();
    
    			}
    		}
    	});
    
    }
    
    
    
    public PizzaOrder() {
    
    	setTitle("Order");
    	setResizable(false);
    	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	setBounds(100, 100, 630, 689);
    	contentPane = new JPanel();
    	contentPane.setBackground(new Color(255, 147, 0));
    	contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    
    	setContentPane(contentPane);
    	contentPane.setLayout(null);
    
    	JPanel Menu = new JPanel();
    	Menu.setBackground(new Color(255, 147, 0));
    	Menu.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 0)), "Menu", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
    	Menu.setBounds(6, 6, 618, 158);
    	contentPane.add(Menu);
    	Menu.setLayout(new GridLayout(0, 3, 0, 0));
    
    	JPanel PizzaPrice = new JPanel();
    	PizzaPrice.setBackground(new Color(255, 147, 0));
    	PizzaPrice.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), "Pizza", TitledBorder.LEADING, TitledBorder.TOP, null, null));
    	Menu.add(PizzaPrice);
    	PizzaPrice.setLayout(null);
    
    	JLabel PetitPizza = new JLabel("Petit: 6.79$");
    	PetitPizza.setBounds(17, 21, 72, 16);
    	PizzaPrice.add(PetitPizza);
    
    	JLabel MoyenPizza = new JLabel("Moyen: 8.29$");
    	MoyenPizza.setBounds(17, 40, 85, 16);
    	PizzaPrice.add(MoyenPizza);
    
    	JLabel LargePizza = new JLabel("Large: 9.49$");
    	LargePizza.setBounds(17, 59, 85, 16);
    	PizzaPrice.add(LargePizza);
    
    	JLabel ExtraLargePizza = new JLabel("Extra Large: 10.29$");
    	ExtraLargePizza.setBounds(17, 78, 127, 16);
    	PizzaPrice.add(ExtraLargePizza);
    
    	JLabel FetePizza = new JLabel("Fete: 15.99$");
    	FetePizza.setBounds(17, 97, 93, 16);
    	PizzaPrice.add(FetePizza);
    
    	JPanel ToppingPrice = new JPanel();
    	ToppingPrice.setBackground(new Color(255, 147, 0));
    	ToppingPrice.setLayout(null);
    	ToppingPrice.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), "Toppings", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
    	Menu.add(ToppingPrice);
    
    	JLabel Petittopping = new JLabel("Petit: 1.20$");
    	Petittopping.setBounds(17, 21, 72, 16);
    	ToppingPrice.add(Petittopping);
    
    	JLabel Moyentopping = new JLabel("Moyen: 1.40$");
    	Moyentopping.setBounds(17, 40, 85, 16);
    	ToppingPrice.add(Moyentopping);
    
    	JLabel Largetopping = new JLabel("Large: 1.60$");
    	Largetopping.setBounds(17, 59, 85, 16);
    	ToppingPrice.add(Largetopping);
    
    	JLabel ExtraLargetopping = new JLabel("Extra Large: 1.80$");
    	ExtraLargetopping.setBounds(17, 78, 127, 16);
    	ToppingPrice.add(ExtraLargetopping);
    
    	JLabel Fetetopping = new JLabel("Fete: 2.30$");
    	Fetetopping.setBounds(17, 97, 93, 16);
    	ToppingPrice.add(Fetetopping);
    
    	JPanel BreuvagePrice = new JPanel();
    	BreuvagePrice.setBackground(new Color(255, 147, 0));
    	BreuvagePrice.setLayout(null);
    	BreuvagePrice.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), "Breuvages", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
    	Menu.add(BreuvagePrice);
    
    	JLabel Pop = new JLabel("Pop: 1.10$");
    	Pop.setBounds(17, 21, 72, 16);
    	BreuvagePrice.add(Pop);
    
    	JLabel Jus = new JLabel("Jus: 1.35$");
    	Jus.setBounds(17, 40, 85, 16);
    	BreuvagePrice.add(Jus);
    
    	JLabel Eau = new JLabel("Eau: 1.00$");
    	Eau.setBounds(17, 59, 85, 16);
    	BreuvagePrice.add(Eau);
    
    	JPanel PizzaSelect = new JPanel();
    	PizzaSelect.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
    	PizzaSelect.setBackground(new Color(255, 147, 0));
    	PizzaSelect.setBounds(16, 187, 350, 300);
    	contentPane.add(PizzaSelect);
    	PizzaSelect.setLayout(null);
    
    	JLabel NombrePizzaTitle = new JLabel("Choix Pizza");
    	NombrePizzaTitle.setForeground(new Color(0, 252, 255));
    	NombrePizzaTitle.setFont(new Font("Hiragino Sans GB", Font.BOLD, 15));
    	NombrePizzaTitle.setBounds(139, 6, 90, 27);
    	PizzaSelect.add(NombrePizzaTitle);
    
    
    	JComboBox<String> ChoixPizza = new JComboBox<String>();
    	ChoixPizza.setModel(new DefaultComboBoxModel(PizzaSize.values()));
    	ChoixPizza.setBounds(122, 90, 126, 27);
    	ChoixPizza.setMaximumRowCount(5);
    	PizzaSelect.add(ChoixPizza);
    
    
    	NumPizza = new JTextField();
    	NumPizza.setBounds(122, 129, 130, 26);
    	PizzaSelect.add(NumPizza);
    	NumPizza.setColumns(10);
    
    	JLabel PizzaIcon = new JLabel("");
    	PizzaIcon.setBounds(6, 6, 350, 279);
    	PizzaSelect.add(PizzaIcon);
    	PizzaIcon.setIcon(new ImageIcon(PizzaOrder.class.getResource("/Image/PizzaImage.png")));
    
    	JPanel ToppingSelect;
    	ToppingSelect = new JPanel();
    	ToppingSelect.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
    	ToppingSelect.setBackground(new Color(255, 147, 0));
    	ToppingSelect.setBounds(400, 187, 208, 129);
    	contentPane.add(ToppingSelect);
    	ToppingSelect.setLayout(null);;
    
    	JLabel NombreToppingTitle = new JLabel("Nombre de topping");
    	NombreToppingTitle.setForeground(new Color(0, 252, 255));
    	NombreToppingTitle.setFont(new Font("Hiragino Sans GB", Font.BOLD, 15));
    	NombreToppingTitle.setBounds(29, 23, 150, 27);
    	ToppingSelect.add(NombreToppingTitle);
    
    	NumTopping = new JTextField();
    	NumTopping.setBounds(39, 50, 130, 26);
    	NumTopping.setColumns(10);
    	ToppingSelect.add(NumTopping);
    
    	JLabel ToppingIcon = new JLabel("");
    	ToppingIcon.setIcon(new ImageIcon(PizzaOrder.class.getResource("/Image/ToppingImage.png")));
    	ToppingIcon.setBounds(6, 8, 208, 109);
    	ToppingSelect.add(ToppingIcon);
    
    	JPanel BreuvageSelect = new JPanel();
    	BreuvageSelect.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
    	BreuvageSelect.setBackground(new Color(255, 147, 0));
    	BreuvageSelect.setBounds(400, 358, 208, 129);
    	contentPane.add(BreuvageSelect);
    	BreuvageSelect.setLayout(null);;
    
    	JLabel NombreToppingTitle_1 = new JLabel("Choix de breuvages");
    	NombreToppingTitle_1.setBounds(34, 6, 150, 27);
    	BreuvageSelect.add(NombreToppingTitle_1);
    	NombreToppingTitle_1.setForeground(new Color(0, 252, 255));
    	NombreToppingTitle_1.setFont(new Font("Hiragino Sans GB", Font.BOLD, 15));
    
    	NumBreuvage = new JTextField();
    	NumBreuvage.setBounds(47, 62, 130, 26);
    	NumBreuvage.setColumns(10);
    	BreuvageSelect.add(NumBreuvage);
    
    	JComboBox<String> ChoixBreuvage = new JComboBox<String>();
    	ChoixBreuvage.setModel(new DefaultComboBoxModel(Breuvages.values()));
    	ChoixBreuvage.setBounds(65, 34, 79, 27);
    	ChoixBreuvage.setMaximumRowCount(3);
    	BreuvageSelect.add(ChoixBreuvage);
    
    	JLabel BreuvageIcon = new JLabel("");
    	BreuvageIcon.setIcon(new ImageIcon(PizzaOrder.class.getResource("/Image/BreuvageImage.png")));
    	BreuvageIcon.setBounds(0, 0, 209, 129);
    	BreuvageSelect.add(BreuvageIcon);
    
    
    	JButton Quitter = new JButton("Quitter");
    	Quitter.addActionListener(new ActionListener() {
    		public void actionPerformed(ActionEvent e) {
    			System.exit(0);
    		}
    	});
    	Quitter.setBounds(33, 552, 160, 50);
    	contentPane.add(Quitter);
    
    
    	Ajouter = new JButton("Ajouter");
    	Ajouter.addActionListener(new ActionListener() {
    		public void actionPerformed(ActionEvent e) {
    		double orderValue = (PizzaSize.getSelectedItem().getPrice() * Integer.parseInt(NumPizza.getText())) +
    		(Double.parseDouble(NumTopping.getText()) * ToppingPriceMap.get(PizzaSize.getSelectedItem())) +
    		(Breuvages.valueOf(ChoixBreuvage.getSelectedItem().toString()).getValue() * Integer.parseInt(NumBreuvage.getText()));
    		orderList.add(orderValue);
    		// Clear the text fields
    		NumPizza.setText("");
    		NumTopping.setText("");
    		NumBreuvage.setText("");
    		}
    		});
    	Ajouter.setBounds(234, 552, 160, 50);
    	contentPane.add(Ajouter);
    
    
    
    
    	JButton Payer = new JButton("Payer");
    	Payer.setBounds(431, 552, 160, 50);
    	contentPane.add(Payer);
    	Payer.addActionListener(new ActionListener() {
    		public void actionPerformed(ActionEvent e) {
    		Receipt receipt = new Receipt(orderList);
    		receipt.setVisible(true);
    		dispose();
    		}
    		});
    	setVisible(false);
    }
    

    }import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.List;

    import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.JLabel; import javax.swing.border.TitledBorder; import javax.swing.ImageIcon; import javax.swing.JList; import javax.swing.border.LineBorder; import java.awt.Color; import java.awt.Font; import javax.swing.BoxLayout; import javax.swing.JButton;

    public class Receipt extends JFrame { private JPanel contentPane; private JList orderList; public void updateList(List newOrderList) { orderList.setListData(newOrderList.toArray(new Double[0])); } /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { Receipt frame = new Receipt(orderList); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); }

    /**
     * Create the frame.
     */
    public Receipt(List<Double> orderList) {
    	setResizable(false);
    	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	setBounds(100, 100, 474, 521);
    	contentPane = new JPanel();
    	contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    	setContentPane(contentPane);
    	contentPane.setLayout(null);
    
        JPanel Panel1 = new JPanel();
        Panel1.setBounds(0, 0, 474, 493);
        contentPane.add(Panel1);
        Panel1.setLayout(null);
        this.orderList = new JList<Double>(orderList.toArray(new Double[0]));
        orderList.setBounds(0, 0, 408, 241);
        Panel1.add(orderList);
        
    
        JLabel TitleCommande = new JLabel("Commande");
        TitleCommande.setFont(new Font("Noteworthy", Font.PLAIN, 25));
        TitleCommande.setBounds(175, 6, 108, 31);
        Panel1.add(TitleCommande);
    
        JList list = new JList();
        list.setBounds(30, 49, 408, 241);
        Panel1.add(list);
    
        JLabel Subtotale = new JLabel("SubTotales: ");
        Subtotale.setBounds(57, 338, 143, 24);
        Panel1.add(Subtotale);
    
        JLabel Totale = new JLabel("Totales: ");
        Totale.setBounds(57, 374, 143, 24);
        Panel1.add(Totale);
    
        JButton ShowTax = new JButton("+Tax(13%)");
        ShowTax.setBounds(199, 337, 117, 29);
        Panel1.add(ShowTax);
    
        JButton ModifyCommande = new JButton("Modifier la Commande");
        ModifyCommande.setBounds(30, 435, 170, 31);
        Panel1.add(ModifyCommande);
        // Add action listener to the "Modifier la Commande" button
        ModifyCommande.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                // Close the Receipt window
                dispose();
    
                // Show the PizzaOrder window
                PizzaOrder pizzaOrder = new PizzaOrder();
                pizzaOrder.setVisible(true);
            }
        });
        
        
        
    
        JButton Fermer = new JButton("Fermer");
        Fermer.setBounds(268, 436, 170, 31);
        Panel1.add(Fermer);
    
        // Add action listener to the "Fermer" button
        Fermer.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                // Close the current window
                dispose();
    
                // Terminate the entire application
                System.exit(0);
            }
        });
    
       
    }
    

    } public enum PizzaSize { Small(6.79), Medium(8.29), Large(9.49), ExtraLarge(10.29), Fete(15.99);

    private final static double price;
    
    private PizzaSize(double price) {
        PizzaSize.price = price;
    }
    
    public static double getPrice() {
        return price;
    }
    
    

    }public enum Breuvages { Pop(1.10), Jus(1.35), Eau(1.00);

    private final double price;
    
    private Breuvages(double price) {
        this.price = price;
    }
    
    public double getPrice() {
        return price;
    }
    

    }

  2. Assistant

    There are several errors in the code. Here's the corrected version:

    import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.List;

    import javax.swing.DefaultComboBoxModel; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.border.BevelBorder; import javax.swing.border.CompoundBorder; import javax.swing.border.EmptyBorder; import javax.swing.border.EtchedBorder; import javax.swing.border.LineBorder; import javax.swing.border.MatteBorder; import javax.swing.border.SoftBevelBorder; import javax.swing.border.TitledBorder;

    import java.awt.Color; import java.awt.Font; import java.awt.GridLayout;

    public class PizzaOrder extends JFrame {

    private JPanel contentPane;
    private JPanel toppingSelect;
    private JTextField numPizza;
    private JTextField numTopping;
    private JTextField numBreuvage;
    private JButton ajouter;
    private List<Double> orderList = new ArrayList<Double>();
    private JComboBox<PizzaSize> pizzaSize;
    private static final long serialVersionUID = 1L;
    
    public static void main(String[] args) {
    	EventQueue.invokeLater(new Runnable() {
    		public void run() {
    			try {
    				PizzaOrder frame = new PizzaOrder();
    				frame.setVisible(true);
    			} catch (Exception e) {
    				e.printStackTrace();
    			}
    		}
    	});
    
    }
    
    public PizzaOrder() {
    
    	setTitle("Order");
    	setResizable(false);
    	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	setBounds(100, 100, 630, 689);
    	contentPane = new JPanel();
    	contentPane.setBackground(new Color(255, 147, 0));
    	contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    
    	setContentPane(contentPane);
    	contentPane.setLayout(null);
    
    	JPanel menu = new JPanel();
    	menu.setBackground(new Color(255, 147, 0));
    	menu.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 0)), "Menu", TitledBorder.LEADING,
    			TitledBorder.TOP, null, new Color(0, 0, 0)));
    	menu.setBounds(6, 6, 618, 158);
    	contentPane.add(menu);
    	menu.setLayout(new GridLayout(0, 3, 0, 0));
    
    	JPanel pizzaPrice = new JPanel();
    	pizzaPrice.setBackground(new Color(255, 147, 0));
    	pizzaPrice.setBorder(
    			new TitledBorder(new Etched
    

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.