Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design and implement a JPanel that displays as shown. When the GUI first display

ID: 653193 • Letter: D

Question

Design and implement a JPanel that displays as shown.

When the GUI first displays, the ?Pounds to Kilograms? a JRadioButton is clicked and the GUI accepts a weight in pounds and converts it to a weight in kilograms, displaying the answer in the JTextArea as shown.


To enter the kilograms for conversion, the user must click the ?Kilograms to Pounds? JRadioButton . The conversion is done when the user presses the convert button.


The ?C? JButton clears the JTextArea between calculations. Note to convert pounds to kilograms multiply by 2.24 and to convert kilograms to pounds divide by 2.24.


Use a JFrame class to display your JPanel class.

Weight Converter weight Converter 12.8 pounds 5.714 kilograms 345 kilograms = 77.28 pounds 3 5 7 7 Convert overt C) Kilograms to Pounds Pounds to Kilograms Kilograms to Pounds Pounds to Kilograms

Explanation / Answer

package com.online.gui;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import com.online.shopping.CheckOut;
import com.online.shopping.ReadingMatter;
import com.online.shopping.ShoppingCart;

public class GUIFrame extends JFrame implements ActionListener {
   JComboBox comboSubType;
   ShoppingCart cart = new ShoppingCart();

   GUIFrame() throws FileNotFoundException {
       super("Online Shopping");
       GridLayout layout = new GridLayout(4, 2);
       setLayout(layout);
       List<String> list = ShoppingCart.types;
       String[] types = ShoppingCart.types.toArray(new String[list.size()]);
       JLabel label1 = new JLabel("Select the type:");
       JComboBox comboTypes = new JComboBox(types);
       add(label1);
       add(comboTypes);
       comboSubType = new JComboBox();
       JLabel label2 = new JLabel("Select the name from list:");
       add(label2);
       add(comboSubType);
       comboTypes.addActionListener(this);
       JButton addCart = new JButton("Add to Cart");
       addCart.setActionCommand("Add to cart");
       addCart.addActionListener(this);
       JButton exitCart = new JButton("Exit");
       exitCart.setActionCommand("Exit");
       exitCart.addActionListener(this);
       add(addCart);
       add(exitCart);
   }

  

   @Override
   public void actionPerformed(ActionEvent e) {
       if (e.getActionCommand().equals("Add to cart")) {
           if (comboSubType.getSelectedItem() == null)
               return;
           System.out.println(comboSubType.getSelectedItem());
           String option = (String) comboSubType.getSelectedItem();
           int id = ShoppingCart.getId(option);
           cart.addToCart(id + 1);
           JOptionPane.showMessageDialog(null, "Added to cart successfully");
       } else if (e.getActionCommand().equals("Exit")) {
           JOptionPane.showMessageDialog(null, cart.toString() + " Pay rs:"
                   + new DecimalFormat("#0.00").format(cart.getTotalPrice()));
           try {
               CheckOut.updateSales(cart);
           } catch (IOException e1) {
               e1.printStackTrace();
           }
           setVisible(false);
       } else {
           JComboBox cb = (JComboBox) e.getSource();
           String option = (String) cb.getSelectedItem();
           comboSubType.removeAllItems();
           List<ReadingMatter> list = ShoppingCart.getTypes(option);
           for (ReadingMatter rd : list)
               comboSubType.addItem(rd.getTitle());
       }
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote